List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:tv.icntv.log.tools.Tools.java
public static void main(String[] args) throws ParseException, IOException { CommandLineParser parser = new PosixParser(); CommandLine line = parser.parse(init(), args); Api api = new FileApi(); long time = System.nanoTime(); String input = line.getOptionValue("I"); List<String> inputStr = Lists.newArrayList(Splitter.on(",").omitEmptyStrings().split(input)); // List<Path> paths = Lists.transform(inputStr,new Function<String, Path>() { // @Override // public Path apply(java.lang.String input) { // System.out.println("input ="+input); // try{ // Path path = new Path(input); //To change body of implemented methods use File | Settings | File Templates. // }catch (Exception e){ // return null; // } // if() // } // }); FileSystem fileSystem = FileSystem.get(new Configuration()); List<Path> paths = Lists.newArrayList(); for (String str : inputStr) { Path path = null;/* ww w. j av a 2s . c o m*/ try { path = new Path(str); if (fileSystem.exists(path)) { System.out.println(" add path .." + str); paths.add(path); } } catch (Exception e) { continue; } } if (null == paths || paths.isEmpty()) { System.out.println("input 2 path null"); } String regular = line.getOptionValue("R"); if (Strings.isNullOrEmpty(regular)) { regular = "part-m-\\d*.lzo"; } System.out.println("regular = " + regular); boolean test = api.writeDat(paths.toArray(new Path[paths.size()]), regular, new Path(line.getOptionValue("Out"))); System.out.println(test + "\t" + (System.nanoTime() - time) / Math.pow(10, 9)); }
From source file:com.google.cloud.bigtable.hbase.CheckConfig.java
/** * <p>main.</p>//from w w w.j a va 2s .co m * * @param args an array of {@link java.lang.String} objects. * @throws java.io.IOException if any. * @throws java.security.GeneralSecurityException if any. */ public static void main(String[] args) throws IOException, GeneralSecurityException { Logger logger = new Logger(CheckConfig.class); GenericOptionsParser optionsParser = new GenericOptionsParser(HBaseConfiguration.create(), args); Configuration fullConfiguration = optionsParser.getConfiguration(); BigtableOptions options; try { options = BigtableOptionsFactory.fromConfiguration(fullConfiguration); } catch (IOException | RuntimeException exc) { logger.warn("Encountered errors attempting to parse configuration.", exc); return; } System.out.println(String.format("User Agent: %s", options.getUserAgent())); System.out.println(String.format("Project ID: %s", options.getProjectId())); System.out.println(String.format("Instance Id: %s", options.getInstanceId())); System.out.println(String.format("Instance admin host: %s", options.getInstanceAdminHost())); System.out.println(String.format("Table admin host: %s", options.getTableAdminHost())); System.out.println(String.format("Data host: %s", options.getDataHost())); Credentials credentials = CredentialFactory.getCredentials(options.getCredentialOptions()); try { System.out.println("Attempting credential refresh..."); credentials.refresh(); } catch (IOException ioe) { logger.warn("Encountered errors attempting to refresh credentials.", ioe); return; } String configuredConnectionClass = fullConfiguration.get(HConnection.HBASE_CLIENT_CONNECTION_IMPL); boolean isCorrectClassSpecified = false; if (!Strings.isNullOrEmpty(configuredConnectionClass)) { try { Class<?> connectionClass = Class.forName(configuredConnectionClass); isCorrectClassSpecified = AbstractBigtableConnection.class.isAssignableFrom(connectionClass); } catch (Exception e) { // Ignore. Problems will be logged in the println below. } } // We can actually determine if this value is correct (disregarding custom subclasses). System.out.println(String.format("HBase Connection Class = %s %s", configuredConnectionClass, isCorrectClassSpecified ? "(OK)" : "(Configuration error)")); System.out.println("Opening table admin connection..."); try (Connection conn = ConnectionFactory.createConnection(fullConfiguration)) { try (Admin admin = conn.getAdmin()) { System.out.println(String.format("Tables in cluster %s:", options.getInstanceId())); TableName[] tableNames = admin.listTableNames(); if (tableNames.length == 0) { System.out.println("No tables found."); } else { for (TableName table : tableNames) { System.out.println(table.getNameAsString()); } } } System.out.println("Closing connection..."); } }
From source file:tv.icntv.logsys.cdn.CdnMapper.java
public static void main(String[] args) { System.out.println(Strings.isNullOrEmpty("")); ////from w w w .ja v a2 s . com // String str = "61.171.246.250 - - [18/Jan/2014:00:00:00 +0800] \"GET /media/new/2013/10/23/hd_dsj_jczm04_20131023.ts HTTP/1.1\" 206 1049126 \"-\" \"010233501205867#00000032AmlogicMDZ-05-201302261821793###Dec 6 2013,1\n" + // "6:41:03\""; // // String reg = "([\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3}\\.[\\d]{1,3})\\s\\-\\s\\-\\s\\[([^]]+)\\]\\s\"([^\"]+)\"\\s(\\d+)\\s(\\d+)\\s\"-\"\\s\"([^]]+)\""; // Pattern pattern = Pattern.compile(reg); // Matcher matcher = pattern.matcher(str); // while(matcher.find()){ // System.out.println("Group 0:"+matcher.group(0)); // System.out.println("Group 1:"+matcher.group(1)); // System.out.println("Group 2:"+matcher.group(2)); // System.out.println("Group 3:"+matcher.group(3)); // System.out.println("Group 4:"+matcher.group(4)); // System.out.println("Group 5:"+matcher.group(5)); // System.out.println("Group 6:"+matcher.group(6)); // } // // Matcher matcher = pattern.matcher(str.toString()); // String g3[],g6[]; // String keyTemp=""; // String valueTemp=""; // if(matcher.find()&& matcher.groupCount()==6){ // g3 = matcher.group(3).split(" "); // g6 = matcher.group(6).split("#"); // if(null==g6 || g6.length==0 || null == g3 || g3.length==0 || g3.length<2){ // return; // } // if(!g6[0].matches("\\d*")){ // return; // } // keyTemp = g6[0]+g3[1]; // // valueTemp = matcher.group(1)+"</>"+matcher.group(2)+"</>"+matcher.group(3)+"</>"+matcher.group(4)+"</>"+matcher.group(5)+"</>"+matcher.group(6); //// context.write(new Text(keyTemp), new Text(valueTemp)); // } // System.out.println(keyTemp); // System.out.println(valueTemp); // String[] arrA = a.split("#"); // for(int i=0;i<arrA.length;i++){ // System.out.println(arrA[i]); // } // // DateFormat format = new SimpleDateFormat("dd/MMM/yyyy:hh:mm:ss Z", Locale.US); DateFormat formatCN = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.CHINA); String rawTime = "27/Jul/2014:03:43:44 +0800"; try { Date date = format.parse(rawTime); System.out.println("format date: " + date); System.out.println("format: " + formatCN.format(date)); } catch (ParseException e) { e.printStackTrace(); } }
From source file:tv.icntv.grade.film.recommend.CFRecommendJob.java
public static void main(String[] args) throws Exception { final Configuration configuration = HBaseConfiguration.create(); configuration.addResource("grade.xml"); String baseCfData = String.format(configuration.get("hdfs.directory.base.score"), new Date()); String output = String.format(configuration.get("icntv.cf.recommend.directory.target"), new Date()); String temp = String.format(configuration.get("icntv.cf.recommend.directory.temp"), new Date()); StringBuilder sb = new StringBuilder(); sb.append("--input ").append(baseCfData); sb.append(" --output ").append(output); sb.append(" --numRecommendations ").append(configuration.get("icntv.cf.recommend.num")); sb.append(" --similarityClassname ").append(configuration.get("icntv.cf.recommend.similarityClassname")); sb.append(" --tempDir ").append(temp); String tables = configuration.get("hbase.cdn.tables"); if (Strings.isNullOrEmpty(tables)) { return;/*from w ww . j a v a 2 s .com*/ } 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); } }); int i = ToolRunner.run(configuration, new CFRecommendJob(), new String[] { Joiner.on(",").join(results), baseCfData, sb.toString(), output, temp }); System.exit(i); }
From source file:io.hops.examples.spark.kafka.StreamingExample.java
public static void main(final String[] args) throws Exception { if (args.length < 1) { LOG.log(Level.SEVERE,/* w w w.ja v a 2 s . c o m*/ "Usage: StreamingExample <type> <sink> <topics> \n" + " <type> type of kafka process (producer|consumer).\n" + " <sink> location in hdfs to append streaming output.\n\n"); System.exit(1); } final String type = args[0]; // Create context with a 2 ; batch interval Set<String> topicsSet = new HashSet<>(Hops.getTopics()); SparkConf sparkConf = new SparkConf().setAppName("StreamingExample"); final List<HopsProducer> sparkProducers = new ArrayList<>(); if (!Strings.isNullOrEmpty(type) && type.equalsIgnoreCase("producer")) { JavaSparkContext jsc = new JavaSparkContext(sparkConf); //Create a producer for each topic for (final String topic : topicsSet) { new Thread() { @Override public void run() { try { SparkProducer sparkProducer = Hops.getSparkProducer(topic); sparkProducers.add(sparkProducer); Map<String, String> message = new HashMap<>(); int i = 0; //Produce Kafka messages to topic while (true) { message.put("platform", "HopsWorks"); message.put("program", "SparkKafka-" + topic + "-" + i); sparkProducer.produce(message); Thread.sleep(1000); i++; } } catch (SchemaNotFoundException | CredentialsNotFoundException | InterruptedException ex) { Logger.getLogger(StreamingExample.class.getName()).log(Level.SEVERE, null, ex); } } }.start(); } //Keep application running Hops.shutdownGracefully(jsc); } else { JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, Durations.seconds(2)); //Use applicationId for sink folder final String appId = jssc.sparkContext().getConf().getAppId(); //Get consumer groups List<String> consumerGroups = Hops.getConsumerGroups(); SparkConsumer consumer = Hops.getSparkConsumer(jssc, topicsSet); // Create direct kafka stream with topics JavaInputDStream<ConsumerRecord<String, byte[]>> messages = consumer.createDirectStream(); //Get the schema for which to consume messages final StringBuilder line = new StringBuilder(); // Get the lines, split them into words, count the words and print JavaDStream<String> lines = messages.map(new Function<ConsumerRecord<String, byte[]>, String>() { @Override public String call(ConsumerRecord<String, byte[]> record) throws SchemaNotFoundException { line.setLength(0); //Parse schema and generate Avro record //For this example, we use a single schema so we get the first record //of the recordInjections map. Otherwise do //recordInjections.get("topic"); GenericRecord genericRecord = recordInjections.entrySet().iterator().next().getValue() .invert(record.value()).get(); line.append(((Utf8) genericRecord.get("platform")).toString()).append(" ") .append(((Utf8) genericRecord.get("program")).toString()); return line.toString(); } }); JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() { @Override public Iterator<String> call(String x) { return Arrays.asList(SPACE.split(x)).iterator(); } }); JavaPairDStream<String, Integer> wordCounts = words .mapToPair(new PairFunction<String, String, Integer>() { @Override public Tuple2<String, Integer> call(String s) { return new Tuple2<>(s, 1); } }).reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); wordCounts.print(); /* * Based on Spark Design patterns * http://spark.apache.org/docs/latest/streaming-programming-guide.html#output-operations-on-dstreams */ wordCounts.foreachRDD(new VoidFunction2<JavaPairRDD<String, Integer>, Time>() { @Override public void call(JavaPairRDD<String, Integer> rdd, Time time) throws Exception { //Keep the latest microbatch output in the file rdd.repartition(1).saveAsHadoopFile(args[1] + "-" + appId, String.class, String.class, TextOutputFormat.class); } }); /* * Enable this to get all the streaming outputs. It creates a folder for * every microbatch slot. * /////////////////////////////////////////////////////////////////////// * wordCounts.saveAsHadoopFiles(args[1], "txt", String.class, * String.class, (Class) TextOutputFormat.class); * /////////////////////////////////////////////////////////////////////// */ // Start the computation jssc.start(); Hops.shutdownGracefully(jssc); } for (HopsProducer hopsProducer : sparkProducers) { hopsProducer.close(); } }
From source file:edu.buaa.satla.analysis.cmd.CPAMain.java
@SuppressWarnings("resource") // We don't close LogManager public static void main(String[] args) { // initialize various components Configuration cpaConfig = null; LogManager logManager = null; String outputDirectory = null; try {/*ww w. j av a 2s . c om*/ try { Pair<Configuration, String> p = createConfiguration(args); cpaConfig = p.getFirst(); outputDirectory = p.getSecond(); } catch (InvalidCmdlineArgumentException e) { System.err.println("Could not process command line arguments: " + e.getMessage()); System.exit(1); } catch (IOException e) { System.err.println("Could not read config file " + e.getMessage()); System.exit(1); } logManager = new BasicLogManager(cpaConfig); } catch (InvalidConfigurationException e) { System.err.println("Invalid configuration: " + e.getMessage()); System.exit(1); return; } cpaConfig.enableLogging(logManager); // create everything ShutdownNotifier shutdownNotifier = ShutdownNotifier.create(); CPAchecker cpachecker = null; ProofGenerator proofGenerator = null; ResourceLimitChecker limits = null; MainOptions options = new MainOptions(); try { cpaConfig.inject(options); if (Strings.isNullOrEmpty(options.programs)) { throw new InvalidConfigurationException("Please specify a program to analyze on the command line."); } dumpConfiguration(options, cpaConfig, logManager); limits = ResourceLimitChecker.fromConfiguration(cpaConfig, logManager, shutdownNotifier); limits.start(); cpachecker = new CPAchecker(cpaConfig, logManager, shutdownNotifier); if (options.doPCC) { proofGenerator = new ProofGenerator(cpaConfig, logManager, shutdownNotifier); } } catch (InvalidConfigurationException e) { logManager.logUserException(Level.SEVERE, e, "Invalid configuration"); System.exit(1); return; } // This is for shutting down when Ctrl+C is caught. ShutdownHook shutdownHook = new ShutdownHook(shutdownNotifier); Runtime.getRuntime().addShutdownHook(shutdownHook); // This is for actually forcing a termination when CPAchecker // fails to shutdown within some time. ShutdownRequestListener forcedExitOnShutdown = ForceTerminationOnShutdown.createShutdownListener(logManager, shutdownHook); shutdownNotifier.register(forcedExitOnShutdown); // run analysis CPAcheckerResult result = cpachecker.run(options.programs); // generated proof (if enabled) if (proofGenerator != null) { proofGenerator.generateProof(result); } // We want to print the statistics completely now that we have come so far, // so we disable all the limits, shutdown hooks, etc. shutdownHook.disable(); shutdownNotifier.unregister(forcedExitOnShutdown); ForceTerminationOnShutdown.cancelPendingTermination(); limits.cancel(); Thread.interrupted(); // clear interrupted flag try { printResultAndStatistics(result, outputDirectory, options, logManager); } catch (IOException e) { logManager.logUserException(Level.WARNING, e, "Could not write statistics to file"); } System.out.flush(); System.err.flush(); logManager.flush(); }
From source file:org.sosy_lab.cpachecker.cmdline.CPAMain.java
@SuppressWarnings("resource") // We don't close LogManager public static void main(String[] args) { // initialize various components Configuration cpaConfig = null; LogManager logManager = null; String outputDirectory = null; try {//from w w w . j a va2s.c o m try { Pair<Configuration, String> p = createConfiguration(args); cpaConfig = p.getFirst(); outputDirectory = p.getSecond(); } catch (InvalidCmdlineArgumentException e) { ERROR_OUTPUT.println("Could not process command line arguments: " + e.getMessage()); System.exit(ERROR_EXIT_CODE); } catch (IOException e) { ERROR_OUTPUT.println("Could not read config file " + e.getMessage()); System.exit(ERROR_EXIT_CODE); } logManager = new BasicLogManager(cpaConfig); } catch (InvalidConfigurationException e) { ERROR_OUTPUT.println("Invalid configuration: " + e.getMessage()); System.exit(ERROR_EXIT_CODE); return; } cpaConfig.enableLogging(logManager); // create everything ShutdownNotifier shutdownNotifier = ShutdownNotifier.create(); CPAchecker cpachecker = null; ProofGenerator proofGenerator = null; ResourceLimitChecker limits = null; MainOptions options = new MainOptions(); try { cpaConfig.inject(options); if (Strings.isNullOrEmpty(options.programs)) { throw new InvalidConfigurationException("Please specify a program to analyze on the command line."); } dumpConfiguration(options, cpaConfig, logManager); limits = ResourceLimitChecker.fromConfiguration(cpaConfig, logManager, shutdownNotifier); limits.start(); cpachecker = new CPAchecker(cpaConfig, logManager, shutdownNotifier); if (options.doPCC) { proofGenerator = new ProofGenerator(cpaConfig, logManager, shutdownNotifier); } } catch (InvalidConfigurationException e) { logManager.logUserException(Level.SEVERE, e, "Invalid configuration"); System.exit(ERROR_EXIT_CODE); return; } // This is for shutting down when Ctrl+C is caught. ShutdownHook shutdownHook = new ShutdownHook(shutdownNotifier); Runtime.getRuntime().addShutdownHook(shutdownHook); // This is for actually forcing a termination when CPAchecker // fails to shutdown within some time. ShutdownRequestListener forcedExitOnShutdown = ForceTerminationOnShutdown.createShutdownListener(logManager, shutdownHook); shutdownNotifier.register(forcedExitOnShutdown); // run analysis CPAcheckerResult result = cpachecker.run(options.programs); // generated proof (if enabled) if (proofGenerator != null) { proofGenerator.generateProof(result); } // We want to print the statistics completely now that we have come so far, // so we disable all the limits, shutdown hooks, etc. shutdownHook.disable(); shutdownNotifier.unregister(forcedExitOnShutdown); ForceTerminationOnShutdown.cancelPendingTermination(); limits.cancel(); Thread.interrupted(); // clear interrupted flag try { printResultAndStatistics(result, outputDirectory, options, logManager); } catch (IOException e) { logManager.logUserException(Level.WARNING, e, "Could not write statistics to file"); } System.out.flush(); System.err.flush(); logManager.flush(); }
From source file:com.cinchapi.concourse.shell.ConcourseShell.java
/** * Run the program.../*w ww. ja v a2s .c om*/ * * @param args * @throws Exception */ public static void main(String... args) throws Exception { try { ConcourseShell cash = new ConcourseShell(); Options opts = new Options(); JCommander parser = null; try { parser = new JCommander(opts, args); } catch (Exception e) { die(e.getMessage()); } parser.setProgramName("concourse-shell"); if (opts.help) { parser.usage(); System.exit(1); } if (!Strings.isNullOrEmpty(opts.prefs)) { opts.prefs = FileOps.expandPath(opts.prefs, System.getProperty("user.dir.real")); ConcourseClientPreferences prefs = ConcourseClientPreferences.open(opts.prefs); opts.username = prefs.getUsername(); opts.password = new String(prefs.getPasswordExplicit()); opts.host = prefs.getHost(); opts.port = prefs.getPort(); opts.environment = prefs.getEnvironment(); } if (Strings.isNullOrEmpty(opts.password)) { cash.setExpandEvents(false); opts.password = cash.console.readLine("Password [" + opts.username + "]: ", '*'); } try { cash.concourse = Concourse.connect(opts.host, opts.port, opts.username, opts.password, opts.environment); cash.whoami = opts.username; } catch (Exception e) { if (e.getCause() instanceof TTransportException) { die("Unable to connect to the Concourse Server at " + opts.host + ":" + opts.port); } else if (e.getCause() instanceof SecurityException) { die("Invalid username/password combination."); } else { die(e.getMessage()); } } if (!opts.ignoreRunCommands) { cash.loadExternalScript(opts.ext); } if (!Strings.isNullOrEmpty(opts.run)) { try { String result = cash.evaluate(opts.run); System.out.println(result); cash.concourse.exit(); System.exit(0); } catch (IrregularEvaluationResult e) { die(e.getMessage()); } } else { cash.enableInteractiveSettings(); boolean running = true; String input = ""; while (running) { boolean extraLineBreak = true; boolean clearInput = true; boolean clearPrompt = false; try { input = input + cash.console.readLine().trim(); String result = cash.evaluate(input); System.out.println(result); } catch (UserInterruptException e) { if (Strings.isNullOrEmpty(e.getPartialLine()) && Strings.isNullOrEmpty(input)) { cash.console.println("Type EXIT to quit."); } } catch (HelpRequest e) { String text = getHelpText(e.topic); if (!Strings.isNullOrEmpty(text)) { Process p = Runtime.getRuntime() .exec(new String[] { "sh", "-c", "echo \"" + text + "\" | less > /dev/tty" }); p.waitFor(); } cash.console.getHistory().removeLast(); } catch (ExitRequest e) { running = false; cash.console.getHistory().removeLast(); } catch (NewLineRequest e) { extraLineBreak = false; } catch (ProgramCrash e) { die(e.getMessage()); } catch (MultiLineRequest e) { extraLineBreak = false; clearInput = false; clearPrompt = true; } catch (IrregularEvaluationResult e) { System.err.println(e.getMessage()); } finally { if (extraLineBreak) { cash.console.print("\n"); } if (clearInput) { input = ""; } if (clearPrompt) { cash.console.setPrompt("> "); } else { cash.console.setPrompt(cash.defaultPrompt); } } } cash.concourse.exit(); System.exit(0); } } finally { TerminalFactory.get().restore(); } }
From source file:adwords.axis.auth.GetRefreshTokenWithoutPropertiesFile.java
public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please input your client ID and secret. " + "If you do not have a client ID or secret, please create one in " + "the API console: https://console.developers.google.com"); System.out.println("Enter your client ID: "); String clientId = reader.readLine(); if (Strings.isNullOrEmpty(clientId)) { System.err.println("Please input your client ID."); System.exit(1);/*from ww w. ja v a 2 s . com*/ } System.out.println("Enter your client secret: "); String clientSecret = reader.readLine(); if (Strings.isNullOrEmpty(clientSecret)) { System.err.println("Please input your client secret."); System.exit(1); } GoogleClientSecrets clientSecrets = null; try { clientSecrets = new GoogleClientSecretsBuilder().forApi(Api.ADWORDS) .withClientSecrets(clientId, clientSecret).build(); } catch (ValidationException e) { System.err.println("Please input your client ID and secret. If you do not have a " + "client ID or secret, please create one in " + "the API console: https://console.developers.google.com"); System.exit(1); } // Get the OAuth2 credential. Credential credential = getOAuth2Credential(clientSecrets); System.out.printf("Your refresh token is: %s\n", credential.getRefreshToken()); }
From source file:tv.icntv.grade.film.recommend.CorrelateJob.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 ww w. j av a 2 s.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 middleDirectory = String.format(configuration.get("icntv.correlate.input"), new Date()); StringBuilder sb = new StringBuilder(); sb.append("minSupport=").append(configuration.get("correlate.minSupport", "3")).append("--") .append("maxHeapSize=100").append("--").append("splitterPattern='[\t ]'").append("--") .append("input=").append(middleDirectory).append("--").append("output=") .append(String.format(configuration.get("icntv.correlate.fp.growth.output"), new Date())); ToolRunner.run(configuration, new CorrelateJob(), new String[] { Joiner.on(",").join(results), middleDirectory, sb.toString(), String.format(configuration.get("icntv.correlate.output"), new Date()) }); }