Example usage for com.google.common.base Strings isNullOrEmpty

List of usage examples for com.google.common.base Strings isNullOrEmpty

Introduction

In this page you can find the example usage for com.google.common.base Strings isNullOrEmpty.

Prototype

public static boolean isNullOrEmpty(@Nullable String string) 

Source Link

Document

Returns true if the given string is null or is the empty string.

Usage

From source file:co.mitro.core.util.RPCLogReplayer.java

public static void main(String[] args) throws IOException, InterruptedException, KeyManagementException,
        UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {

    List<Request> requests = new ArrayList<>();
    ExecutorService executor = Executors.newFixedThreadPool(5);
    for (int i = 0; i < args.length; ++i) {
        String filename = args[i];
        System.err.println("Reading file: " + filename);
        JsonRecordReader rr = JsonRecordReader.MakeFromFilename(filename);
        JsonRecordReader.JsonLog log;//from  w w  w . j a  v  a 2s.  c  om
        try {
            while (null != (log = rr.readJson())) {
                if (Strings.isNullOrEmpty(log.payload.transactionId) && !log.payload.implicitBeginTransaction) {
                    // read only transaction
                    requests.add(new Request(log.metadata.endpoint, log.payload));
                }
            }
        } catch (EOFException e) {
            System.err.println("unexpected end of file; skipping");
        }
    }

    // run the simulation for a while.
    long scaling = 1000;
    double requestsPerMs = 353. / 9805199;
    long START_MS = 0;
    // run for 20 min
    long END_MS = 20 * 60 * 1000;
    long now = START_MS;
    int count = 0;
    while (now < END_MS) {
        double toSleep = nextExp(requestsPerMs * scaling);
        now += toSleep;
        ++count;
        Thread.sleep((long) toSleep);
        executor.execute(new SendQuery(requests.get(RNG.nextInt(requests.size()))));
        System.out.println("count: " + count + "\t time:" + now + "\t rate:" + (double) count / now);
    }
    executor.awaitTermination(1, TimeUnit.MINUTES);

}

From source file:tv.icntv.grade.film.grade.GradeJob.java

public static void main(String[] args) throws Exception {
    final Configuration configuration = HBaseConfiguration.create();
    configuration.addResource("grade.xml");
    String tables = configuration.get("hbase.cdn.tables");
    if (Strings.isNullOrEmpty(tables)) {
        return;//from   www .j  a va 2s .  c o  m
    }
    List<String> list = Lists.newArrayList(Splitter.on(",").split(tables));
    List<String> results = Lists.transform(list, new Function<String, String>() {
        @Override
        public String apply(@Nullable java.lang.String input) {
            return String.format(configuration.get("hdfs.directory.base.db"), new Date(), input);
        }
    });

    String[] arrays = new String[] { Joiner.on(",").join(results), configuration.get("film.see.num.table"),
            String.format(configuration.get("hdfs.directory.base.score"), new Date()),
            String.format(configuration.get("icntv.correlate.input"), new Date()) };
    int i = ToolRunner.run(configuration, new GradeJob(), arrays);
    System.exit(i);
}

From source file:semRewrite.RewriteRuleUtil.java

/************************************************************
 *///  w  ww  .  j  a  va 2  s  .  co m
public static void main(String[] args) {

    ArrayList<Integer> getSubsumed = new ArrayList<Integer>();
    ArrayList<Integer> subsumer = new ArrayList<Integer>();
    RuleSet rs = loadRuleSet();
    String input = "";
    System.out.println("SemRewrite.txt loaded. There are " + rs.rules.size() + " rules.");
    //       SemRewriteRuleCheck.checkRuleSet(rs);
    Scanner scanner = new Scanner(System.in);
    do {
        System.out.println("Semantic Rewriting Rule Uitl");
        System.out.println("  options:");
        System.out.println("  rewriterule                     check rule subsumption");
        System.out.println(
                "  !filepath                       get the sentences in file and find a common CNF, the file should be one sentence one line");
        System.out.println(
                "  'reload'                        reload the SemrewriteRule.txt and check the whole RuleSet");
        System.out.println(
                "  @@inputfilepath,outputfilepath  load the sentences from inputfile, do whole interpreter thing on sentences and generate output json file");
        System.out.println("  'exit'/'quit'                   quit this program");
        try {
            System.out.print("\nEnter :");
            input = scanner.nextLine().trim();
            if (!Strings.isNullOrEmpty(input) && !input.equals("exit") && !input.equals("quit")) {
                if (input.equals("reload")) {
                    rs = loadRuleSet();
                    SemRewriteRuleCheck.checkRuleSet(rs);
                    continue;
                }
                if (input.startsWith("!")) {
                    String path = input.substring(1);
                    CNF cnf = CommonCNFUtil.loadFileAndFindCommonCNF(path);
                    continue;
                }
                if (input.startsWith("@@")) {
                    String path = input.substring(2);
                    String[] paths = path.split(",");
                    QAOutputGenerator.generate(paths[0], paths[1], null);
                    continue;
                }
                Rule r = Rule.parseString(input);
                System.out.println("The rule entered is :: " + r + "\n");
                SemRewriteRuleCheck.isRuleSubsumedByRuleSet(r, rs, getSubsumed, subsumer);

                System.out.println(
                        "Following " + getSubsumed.size() + " rules would subsume the rule entered: \n");
                for (int k : getSubsumed) {
                    System.out.println("Line Number:" + rs.rules.get(k).startLine + " : " + rs.rules.get(k));
                }
                System.out.println("---------------------------------------------------------------");
                System.out.println(
                        "Following " + subsumer.size() + " rules would be subsumed by the rule entered: \n");
                for (int k : subsumer) {
                    System.out.println("Line Number:" + rs.rules.get(k).startLine + " : " + rs.rules.get(k));
                }
                System.out.println("\n");
            }
        } catch (Throwable e) {
            continue;
        }

    } while (!input.equals("exit") && !input.equals("quit"));
}

From source file:com.google.cloud.genomics.dataflow.pipelines.CountReads.java

public static void main(String[] args) throws GeneralSecurityException, IOException {
    // Register the options so that they show up via --help
    PipelineOptionsFactory.register(Options.class);
    pipelineOptions = PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
    // Option validation is not yet automatic, we make an explicit call here.
    Options.Methods.validateOptions(pipelineOptions);

    auth = GenomicsOptions.Methods.getGenomicsAuth(pipelineOptions);
    p = Pipeline.create(pipelineOptions);
    p.getCoderRegistry().setFallbackCoderProvider(GenericJsonCoder.PROVIDER);

    // ensure data is accessible
    String BAMFilePath = pipelineOptions.getBAMFilePath();
    if (!Strings.isNullOrEmpty(BAMFilePath)) {
        if (GCSURLExists(BAMFilePath)) {
            System.out.println(BAMFilePath + " is present, good.");
        } else {//w  w w  .  j  a  v a2  s .c o  m
            System.out.println("Error: " + BAMFilePath + " not found.");
            return;
        }
        if (pipelineOptions.isShardBAMReading()) {
            // the BAM code expects an index at BAMFilePath+".bai"
            // and sharded reading will fail if the index isn't there.
            String BAMIndexPath = BAMFilePath + ".bai";
            if (GCSURLExists(BAMIndexPath)) {
                System.out.println(BAMIndexPath + " is present, good.");
            } else {
                System.out.println("Error: " + BAMIndexPath + " not found.");
                return;
            }
        }
    }
    System.out.println("Output will be written to " + pipelineOptions.getOutput());

    PCollection<Read> reads = getReads();
    PCollection<Long> readCount = reads.apply(Count.<Read>globally());
    PCollection<String> readCountText = readCount.apply(ParDo.of(new DoFn<Long, String>() {
        @Override
        public void processElement(DoFn<Long, String>.ProcessContext c) throws Exception {
            c.output(String.valueOf(c.element()));
        }
    }).named("toString"));
    readCountText.apply(TextIO.Write.to(pipelineOptions.getOutput()).named("WriteOutput").withoutSharding());

    p.run();
}

From source file:com.github.jcustenborder.kafka.connect.spooldir.SchemaGenerator.java

public static void main(String... args) throws Exception {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("CsvSchemaGenerator").defaultHelp(true)
            .description("Generate a schema based on a file.");
    parser.addArgument("-t", "--type").required(true).choices("csv", "json")
            .help("The type of generator to use.");
    parser.addArgument("-c", "--config").type(File.class);
    parser.addArgument("-f", "--file").type(File.class).required(true)
            .help("The data file to generate the schema from.");
    parser.addArgument("-i", "--id").nargs("*").help("Field(s) to use as an identifier.");
    parser.addArgument("-o", "--output").type(File.class)
            .help("Output location to write the configuration to. Stdout is default.");

    Namespace ns = null;/*from ww w. j av  a2  s . co  m*/

    try {
        ns = parser.parseArgs(args);
    } catch (ArgumentParserException ex) {
        parser.handleError(ex);
        System.exit(1);
    }

    File inputFile = ns.get("file");
    List<String> ids = ns.getList("id");
    if (null == ids) {
        ids = ImmutableList.of();
    }

    Map<String, Object> settings = new LinkedHashMap<>();

    File inputPropertiesFile = ns.get("config");
    if (null != inputPropertiesFile) {
        Properties inputProperties = new Properties();

        try (FileInputStream inputStream = new FileInputStream(inputPropertiesFile)) {
            inputProperties.load(inputStream);
        }
        for (String s : inputProperties.stringPropertyNames()) {
            Object v = inputProperties.getProperty(s);
            settings.put(s, v);
        }
    }

    final SchemaGenerator generator;
    final String type = ns.getString("type");

    if ("csv".equalsIgnoreCase(type)) {
        generator = new CsvSchemaGenerator(settings);
    } else if ("json".equalsIgnoreCase(type)) {
        generator = new JsonSchemaGenerator(settings);
    } else {
        throw new UnsupportedOperationException(
                String.format("'%s' is not a supported schema generator type", type));
    }

    Map.Entry<Schema, Schema> kvp = generator.generate(inputFile, ids);

    Properties properties = new Properties();
    properties.putAll(settings);
    properties.setProperty(SpoolDirSourceConnectorConfig.KEY_SCHEMA_CONF,
            ObjectMapperFactory.INSTANCE.writeValueAsString(kvp.getKey()));
    properties.setProperty(SpoolDirSourceConnectorConfig.VALUE_SCHEMA_CONF,
            ObjectMapperFactory.INSTANCE.writeValueAsString(kvp.getValue()));

    String output = ns.getString("output");
    final String comment = "Configuration was dynamically generated. Please verify before submitting.";

    if (Strings.isNullOrEmpty(output)) {
        properties.store(System.out, comment);
    } else {
        try (FileOutputStream outputStream = new FileOutputStream(output)) {
            properties.store(outputStream, comment);
        }
    }
}

From source file:org.apache.nifi.toolkit.zkmigrator.ZooKeeperMigratorMain.java

public static void main(String[] args) throws IOException {
    PrintStream output = System.out;
    System.setOut(System.err);

    final Options options = createOptions();
    final CommandLine commandLine;
    try {//from  w ww.j  a v  a  2 s . c  o  m
        commandLine = new DefaultParser().parse(options, args);
        if (commandLine.hasOption(OPTION_ZK_MIGRATOR_HELP.getLongOpt())) {
            printUsage(null, options);
        } else {
            final String zookeeperUri = commandLine.getOptionValue(OPTION_ZK_ENDPOINT.getOpt());
            final Mode mode = commandLine.hasOption(OPTION_RECEIVE.getOpt()) ? Mode.READ : Mode.WRITE;
            final String filename = commandLine.getOptionValue(OPTION_FILE.getOpt());
            final String auth = commandLine.getOptionValue(OPTION_ZK_AUTH_INFO.getOpt());
            final String jaasFilename = commandLine.getOptionValue(OPTION_ZK_KRB_CONF_FILE.getOpt());
            final boolean ignoreSource = commandLine.hasOption(OPTION_IGNORE_SOURCE.getLongOpt());
            final AuthMode authMode;
            final byte[] authData;
            if (auth != null) {
                authMode = AuthMode.DIGEST;
                authData = auth.getBytes(StandardCharsets.UTF_8);
            } else {
                authData = null;
                if (!Strings.isNullOrEmpty(jaasFilename)) {
                    authMode = AuthMode.SASL;
                    System.setProperty("java.security.auth.login.config", jaasFilename);
                } else {
                    authMode = AuthMode.OPEN;
                }
            }
            final ZooKeeperMigrator zookeeperMigrator = new ZooKeeperMigrator(zookeeperUri);
            if (mode.equals(Mode.READ)) {
                try (OutputStream zkData = filename != null ? new FileOutputStream(Paths.get(filename).toFile())
                        : output) {
                    zookeeperMigrator.readZooKeeper(zkData, authMode, authData);
                }
            } else {
                try (InputStream zkData = filename != null ? new FileInputStream(Paths.get(filename).toFile())
                        : System.in) {
                    zookeeperMigrator.writeZooKeeper(zkData, authMode, authData, ignoreSource);
                }
            }
        }
    } catch (ParseException e) {
        printUsage(e.getLocalizedMessage(), options);
    } catch (IOException | KeeperException | InterruptedException | ExecutionException e) {
        throw new IOException(String.format("unable to perform operation: %s", e.getLocalizedMessage()), e);
    }
}

From source file:qa.qcri.nadeef.console.Console.java

/**
 * Start of Console.//from ww  w  . jav a  2  s.co m
 * @param args user input.
 */
public static void main(String[] args) {
    try {
        // bootstrap Nadeef.
        Stopwatch stopwatch = Stopwatch.createStarted();
        Bootstrap.start();

        console = new ConsoleReader();
        Tracer.setConsole(new ConsoleReaderAdaptor(console));
        List<Completer> loadCompleter = Arrays.asList(new StringsCompleter(commands), new FileNameCompleter(),
                new NullCompleter());
        console.addCompleter(new ArgumentCompleter(loadCompleter));

        console.clearScreen();
        console.println(logo);
        console.println();
        console.println(helpInfo);
        console.println();
        console.drawLine();
        console.setPrompt(prompt);
        console.println("Your NADEEF started in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms.");

        String line;
        while ((line = console.readLine()) != null) {
            line = line.trim();
            String[] tokens = line.split(" ");

            if (tokens.length == 0) {
                continue;
            }

            // clear the statistics for every run.
            PerfReport.clear();
            try {
                if (tokens[0].equalsIgnoreCase("exit")) {
                    break;
                } else if (tokens[0].equalsIgnoreCase("load")) {
                    load(line);
                } else if (tokens[0].equalsIgnoreCase("list")) {
                    list();
                } else if (tokens[0].equalsIgnoreCase("help")) {
                    printHelp();
                } else if (tokens[0].equalsIgnoreCase("detect")) {
                    detect(line);
                } else if (tokens[0].equalsIgnoreCase("repair")) {
                    repair(line);
                } else if (tokens[0].equalsIgnoreCase("run")) {
                    run(line);
                } else if (tokens[0].equalsIgnoreCase("append")) {
                    append(line);
                } else if (tokens[0].equalsIgnoreCase("set")) {
                    set(line);
                } else if (!Strings.isNullOrEmpty(tokens[0])) {
                    console.println("I don't know this command.");
                }
            } catch (Exception ex) {
                console.println("Oops, something is wrong. Please check the log in the output dir.");

                tracer.err("", ex);
            }
        }
    } catch (Exception ex) {
        try {
            tracer.err("Bootstrap failed", ex);
        } catch (Exception ignore) {
        }
    } finally {
        Bootstrap.shutdown();
    }

    System.exit(0);
}

From source file:org.gitools.ui.app.Main.java

public static void main(final String[] args) {

    // Start CommandListener
    boolean portEnabled = Settings.get().isPortEnabled();
    String portString = null;/*ww  w  . jav  a 2 s  . c o  m*/
    if (portEnabled || portString != null) {
        int port = Settings.get().getDefaultPort();
        if (portString != null) {
            port = Integer.parseInt(portString);
        }
        CommandListener.start(port, args);
    }

    // Initialize look and feel
    WebLookAndFeel.install();
    WebLookAndFeel.initializeManagers();
    NotificationManager.setLocation(NotificationManager.NORTH_EAST);
    WebCheckBoxStyle.animated = false;

    // Splash screen , loading dialog

    // Exampler loading dialog
    final WebProgressDialog progress = createProgressDialog();
    progress.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(final WindowEvent e) {
            // Stop loading demo on dialog close
            System.exit(0);
        }
    });
    progress.setVisible(true);

    setProgressText(progress, "Loading Gitools interface");
    // Initialize Weld and ApplicationContext
    WeldContainer container = new StartMain(args).go();
    ApplicationContext.setPersistenceManager(container.instance().select(PersistenceManager.class).get());
    ApplicationContext.setPluginManger(container.instance().select(PluginManager.class).get());
    ApplicationContext.setEditorManger(container.instance().select(IEditorManager.class).get());
    ApplicationContext.setProgressMonitor(new NullProgressMonitor());

    setProgressText(progress, "Loading command executor");
    // Check arguments syntax
    final CommandExecutor cmdExecutor = new CommandExecutor();
    if (args.length > 0) {
        if (!cmdExecutor.checkArguments(args, new PrintWriter(System.err))) {
            return;
        }
    }

    // Workaround to force windows to paint the TaskPaneContainer background
    UIManager.put("TaskPaneContainer.backgroundPainter", new MattePainter(Color.WHITE));

    // Workaround to put a dropdown into a JToolBar
    UIManager.put("PopupMenu.consumeEventOnClose", Boolean.TRUE);

    // Force silence lobobrowser loggers
    try {
        LogManager.getLogManager()
                .readConfiguration(new ByteArrayInputStream("org.lobobrowser.level=OFF".getBytes("UTF-8")));
    } catch (IOException e) {
    }

    // Load OS specific things
    if (SystemInfo.isMac) {
        com.apple.eawt.Application osxApp = com.apple.eawt.Application.getApplication();
        osxApp.setDockIconImage(IconUtils.getImageResource(IconNames.logoNoText));
    }

    // Initialize help system
    setProgressText(progress, "Loading help system");
    try {
        Tips.get().load(Main.class.getResourceAsStream("/help/tips.properties"));
        Help.get().loadProperties(Main.class.getResourceAsStream("/help/help.properties"));
        Help.get().loadUrlMap(Main.class.getResourceAsStream("/help/help.mappings"));
    } catch (Exception ex) {
        System.err.println("Error loading help system:");
        ex.printStackTrace();
    }

    // Initialize actions
    setProgressText(progress, "Loading Gitools actions");
    Actions.init();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

            // Launch frame
            Application app = Application.get();
            app.setJMenuBar(MenuActionSet.INSTANCE.createMenuBar());
            app.setToolBar(ToolBarActionSet.INSTANCE.createToolBar());
            Application.get().addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    Actions.exitAction.actionPerformed(null);
                }
            });
            app.initApplication();

            app.addEditor(new WelcomeEditor());
            app.start();

            if (args.length > 0) {

                // Execute arguments
                cmdExecutor.execute(args, new PrintWriter(System.err));

                Application.get().trackEvent("main", isRunningJavaWebStart() ? "webstart" : "start",
                        "with arguments");

            } else {

                if (Strings.isNullOrEmpty(Settings.get().getStatisticsConsentmentVersion())
                        || (!Settings.get().isAllowUsageStatistics() && !Application.getGitoolsVersion()
                                .equals(Settings.get().getStatisticsConsentmentVersion()))) {

                    Settings.get().setAllowUsageStatistics(true);
                    JPanel panel = new GitoolsSatsSection(Settings.get()).getPanel();
                    JOptionPane.showMessageDialog(Application.get(), panel, "Statistics",
                            JOptionPane.QUESTION_MESSAGE);
                    Settings.get().setStatisticsConsentmentVersion(Application.getGitoolsVersion().toString());

                } else {

                    // Show tips dialog
                    TipsDialog tipsDialog = new TipsDialog();
                    tipsDialog.show();

                }

                Application.get().trackEvent("main", isRunningJavaWebStart() ? "webstart" : "start",
                        "no arguments");
            }

        }
    });

    // Displaying Gitools and hiding loading dialog
    progress.setVisible(false);

}

From source file:org.apache.ctakes.ytex.kernel.dao.ConceptDaoImpl.java

/**
 * create a concept graph./*from   w w  w.ja v a2  s.c o  m*/
 * 
 * This expects a property file in the classpath under
 * CONCEPT_GRAPH_PATH/[name].xml
 * <p/>
 * If the properties file is found in a directory, the concept graph will be
 * written there.
 * <p/>
 * Else (e.g. if the props file is coming from a jar), the concept graph
 * will be written to the directory specified via the system property/ytex
 * property 'org.apache.ctakes.ytex.conceptGraphDir'
 * <p/>
 * Else if the 'org.apache.ctakes.ytex.conceptGraphDir' property is not
 * defined, the concept graph will be written to the conceptGraph
 * subdirectory relative to ytex.properties (if ytex.properties is in a
 * directory).
 * 
 * @param args
 */
@SuppressWarnings("static-access")
public static void main(String args[]) throws ParseException, IOException {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("name").hasArg().isRequired()
            .withDescription("name of concept graph.  A property file with the name " + CONCEPT_GRAPH_PATH
                    + "/[name].xml must exist on the classpath")
            .create("name"));
    try {
        CommandLineParser parser = new GnuParser();
        CommandLine line = parser.parse(options, args);
        String name = line.getOptionValue("name");
        String propRes = CONCEPT_GRAPH_PATH + name + ".xml";
        URL url = ConceptDaoImpl.class.getClassLoader().getResource(propRes);
        if (url == null) {
            System.out.println("properties file could not be located: " + propRes);
            return;
        }
        // load properties
        Properties props = new Properties();
        InputStream is = ConceptDaoImpl.class.getClassLoader().getResourceAsStream(propRes);
        try {
            props.loadFromXML(is);
        } finally {
            is.close();
        }
        // determine directory for concept graph - attempt to put in same
        // dir as props
        File fDir = null;
        if ("file".equals(url.getProtocol())) {
            File f;
            try {
                f = new File(url.toURI());
            } catch (URISyntaxException e) {
                f = new File(url.getPath());
            }
            fDir = f.getParentFile();
        }
        String conceptGraphQuery = props.getProperty("ytex.conceptGraphQuery");
        String strCheckCycle = props.getProperty("ytex.checkCycle", "true");
        String forbiddenConceptList = props.getProperty("ytex.forbiddenConcepts");
        Set<String> forbiddenConcepts;
        if (forbiddenConceptList != null) {
            forbiddenConcepts = new HashSet<String>();
            forbiddenConcepts.addAll(Arrays.asList(forbiddenConceptList.split(",")));
        } else {
            forbiddenConcepts = defaultForbiddenConcepts;
        }
        boolean checkCycle = true;
        if ("false".equalsIgnoreCase(strCheckCycle) || "no".equalsIgnoreCase(strCheckCycle))
            checkCycle = false;
        if (!Strings.isNullOrEmpty(name) && !Strings.isNullOrEmpty(conceptGraphQuery)) {
            KernelContextHolder.getApplicationContext().getBean(ConceptDao.class).createConceptGraph(
                    fDir != null ? fDir.getAbsolutePath() : null, name, conceptGraphQuery, checkCycle,
                    forbiddenConcepts);
        } else {
            printHelp(options);
        }
    } catch (ParseException pe) {
        printHelp(options);
    }
}

From source file:com.trulia.stail.Stail.java

public static void main(String[] args) {
    final Stail stail = new Stail();

    JCommander jct = new JCommander(stail);
    jct.setProgramName("stail");
    try {//from w ww . j a  va2  s.  co m
        jct.parse(args);

        AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
        if (stail.profile != null) {
            credentialsProvider = new ProfileCredentialsProvider(stail.profile);
        }

        if (stail.role != null) {
            credentialsProvider = new STSAssumeRoleSessionCredentialsProvider.Builder(stail.role, "stail")
                    .withStsClient(AWSSecurityTokenServiceClientBuilder.standard()
                            .withCredentials(credentialsProvider).build())
                    .build();
        }

        AmazonKinesis client = AmazonKinesisClientBuilder.standard().withRegion(stail.region)
                .withCredentials(credentialsProvider).build();

        // prepare the initial shard iterators at the LATEST position
        Map<Shard, String> shardIterators = getShardIterators(client, stail.stream, stail.start);

        IRecordProcessor processor = stail.json ? new JSONRecordProcessor() : new RawRecordProcessor();

        Map<Shard, RateLimiter> rateLimiters = new HashMap<>();
        shardIterators.keySet()
                .forEach(shard -> rateLimiters.put(shard, RateLimiter.create(MAX_SHARD_THROUGHPUT)));

        long end = Strings.isNullOrEmpty(stail.duration) ? Long.MAX_VALUE
                : System.currentTimeMillis() + Duration.parse(stail.duration).toMillis();

        Set<String> reshardedShards = new HashSet<>();

        Map<Shard, String> sequenceNumbers = new HashMap<>();

        while (System.currentTimeMillis() < end) {
            if (!reshardedShards.isEmpty()) {
                // get the new list of shards
                List<Shard> shards = getShards(client, stail.stream);
                for (Shard shard : shards) {
                    if (!Strings.isNullOrEmpty(shard.getParentShardId())
                            && reshardedShards.contains(shard.getParentShardId())) {
                        // the old shard was split, so we need to consume this new shard from the beginning
                        shardIterators.put(shard, getOldestShardIterator(client, stail.stream, shard));
                    } else if (!Strings.isNullOrEmpty(shard.getAdjacentParentShardId())
                            && reshardedShards.contains(shard.getAdjacentParentShardId())) {
                        // the old shards were merged into a new shard
                        shardIterators.put(shard, getOldestShardIterator(client, stail.stream, shard));
                    }
                }

                reshardedShards.clear();
            }

            for (Shard shard : Lists.newArrayList(shardIterators.keySet())) {
                String shardIterator = shardIterators.remove(shard);

                GetRecordsRequest getRecordsRequest = new GetRecordsRequest();
                getRecordsRequest.setShardIterator(shardIterator);
                getRecordsRequest.setLimit(BATCH_SIZE);

                try {
                    GetRecordsResult getRecordsResult = client.getRecords(getRecordsRequest);
                    List<Record> records = getRecordsResult.getRecords();
                    processor.processRecords(records, null);

                    shardIterator = getRecordsResult.getNextShardIterator();

                    if (records.size() <= 0) {
                        // nothing on the stream yet, so lets wait a bit to see if something appears
                        TimeUnit.SECONDS.sleep(1);
                    } else {
                        int bytesRead = records.stream().map(record -> record.getData().position())
                                .reduce((_1, _2) -> _1 + _2).get();

                        sequenceNumbers.put(shard, records.get(records.size() - 1).getSequenceNumber());

                        // optionally sleep if we have hit the limit for this shard
                        rateLimiters.get(shard).acquire(bytesRead);
                    }

                    if (!Strings.isNullOrEmpty(shardIterator)) {
                        shardIterators.put(shard, shardIterator);
                    } else {
                        reshardedShards.add(shard.getShardId());
                    }
                } catch (ProvisionedThroughputExceededException e) {
                    logger.warn("tripped the max throughput.  Backing off: {}", e.getMessage());
                    TimeUnit.SECONDS.sleep(6); // we tripped the max throughput.  Back off

                    // add the original iterator back into the map so we can try it again
                    shardIterators.put(shard, shardIterator);
                } catch (ExpiredIteratorException e) {
                    logger.debug("Iterator expired", e);

                    String sequenceNumber = sequenceNumbers.get(shard);
                    if (sequenceNumber == null) {
                        logger.warn("No previously known sequence number for {}.  Moving to LATEST",
                                shard.getShardId());
                        shardIterators.put(shard, getShardIterator(client, stail.stream, shard, null));
                    } else {
                        shardIterators.put(shard,
                                getShardIteratorAtSequenceNumber(client, stail.stream, shard, sequenceNumber));
                    }
                }
            }
        }
    } catch (ParameterException e) {
        jct.usage();
        System.exit(1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        System.exit(2);
    }
}