List of usage examples for java.util Properties containsKey
@Override public boolean containsKey(Object key)
From source file:org.apache.ctakes.ytex.kernel.InfoContentEvaluatorImpl.java
/** * @param args//from ww w . ja v a2 s .c o m * @throws IOException */ @SuppressWarnings("static-access") public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("property file").hasArg().isRequired() .withDescription("property file with queries and other parameters. todo desc").create("prop")); try { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); Properties props = (Properties) KernelContextHolder.getApplicationContext().getBean("ytexProperties"); Properties propsArgs = FileUtil.loadProperties(line.getOptionValue("prop"), true); props.putAll(propsArgs); if (!props.containsKey("org.apache.ctakes.ytex.conceptGraphName") || !props.containsKey("org.apache.ctakes.ytex.corpusName") || !props.containsKey("org.apache.ctakes.ytex.freqQuery")) { System.err.println("error: required parameter not specified"); System.exit(1); } else { InfoContentEvaluator corpusEvaluator = KernelContextHolder.getApplicationContext() .getBean(InfoContentEvaluator.class); corpusEvaluator.evaluateCorpusInfoContent(props.getProperty("org.apache.ctakes.ytex.freqQuery"), props.getProperty("org.apache.ctakes.ytex.corpusName"), props.getProperty("org.apache.ctakes.ytex.conceptGraphName"), props.getProperty("org.apache.ctakes.ytex.conceptSetName")); System.exit(0); } } catch (ParseException pe) { printHelp(options); System.exit(1); } }
From source file:io.personium.recovery.Recovery.java
/** * main.//from w w w .j ava 2s . co m * @param args */ public static void main(String[] args) { loadProperties(); Option optIndex = new Option("i", "index", true, "?"); Option optProp = new Option("p", "prop", true, ""); // t?????????????????????? Option optType = new Option("t", "type", true, "??type"); Option optClear = new Option("c", "clear", false, "???elasticsearch?"); Option optReplicas = new Option("r", "replicas", true, "??"); Option optVersion = new Option("v", "version", false, "??"); // // optIndex.setRequired(true); // optProp.setRequired(true); Options options = new Options(); options.addOption(optIndex); options.addOption(optProp); options.addOption(optType); options.addOption(optClear); options.addOption(optReplicas); options.addOption(optVersion); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args, true); } catch (ParseException e) { (new HelpFormatter()).printHelp("io.personium.recovery.Recovery", options); log.warn("Recovery failure"); System.exit(1); } if (commandLine.hasOption("v")) { log.info("Version:" + versionNumber); System.exit(0); } if (!commandLine.hasOption("p")) { (new HelpFormatter()).printHelp("io.personium.recovery.Recovery", options); log.warn("Recovery failure"); System.exit(1); } if (commandLine.hasOption("t")) { log.info("Command line option \"t\" or \"type\" is deprecated. Option ignored."); } if (!commandLine.hasOption("r")) { (new HelpFormatter()).printHelp("io.personium.recovery.Recovery", options); log.warn("Command line option \"r\" is required."); System.exit(1); } RecoveryManager recoveryManager = new RecoveryManager(); // ??index recoveryManager.setIndexNames(commandLine.getOptionValue("i")); // elasticsearch recoveryManager.setClear(commandLine.hasOption("c")); // ?? // 0 ?ES??????????int??????? try { int replicas = Integer.parseInt(commandLine.getOptionValue("r")); if (replicas < 0) { log.warn("Command line option \"r\"'s value is not integer."); System.exit(1); } recoveryManager.setReplicas(replicas); } catch (NumberFormatException e) { log.warn("Command line option \"r\"'s value is not integer."); System.exit(1); } try { // Properties? Properties properties = new Properties(); // ? properties.load(new FileInputStream(commandLine.getOptionValue("p"))); if ((!properties.containsKey(ES_HOSTS)) || (!properties.containsKey(ES_CLUSTER_NAME)) || (!properties.containsKey(ADS_JDBC_URL)) || (!properties.containsKey(ADS_JDBC_USER)) || (!properties.containsKey(ADS_JDBC_PASSWORD)) || (!properties.containsKey(ES_ROUTING_FLAG))) { log.warn("properties file error"); log.warn("Recovery failure"); System.exit(1); } else { recoveryManager.setEsHosts(properties.getProperty(ES_HOSTS)); recoveryManager.setEsClusetrName(properties.getProperty(ES_CLUSTER_NAME)); recoveryManager.setAdsJdbcUrl(properties.getProperty(ADS_JDBC_URL)); recoveryManager.setAdsUser(properties.getProperty(ADS_JDBC_USER)); recoveryManager.setAdsPassword(properties.getProperty(ADS_JDBC_PASSWORD)); recoveryManager.setExecuteCnt(properties.getProperty(EXECUTE_COUNT)); recoveryManager.setCheckCount(properties.getProperty(CHECK_COUNT)); recoveryManager.setUnitPrefix(properties.getProperty(UNIT_PREFIX)); } } catch (FileNotFoundException e) { e.printStackTrace(); log.warn("properties file error"); log.warn("Recovery failure"); System.exit(1); } catch (IOException e) { e.printStackTrace(); log.warn("properties file error"); log.warn("Recovery failure"); System.exit(1); } String[] indexList = recoveryManager.getIndexNames(); boolean isClear = recoveryManager.isClear(); if (isClear && (indexList != null && null != indexList[0])) { String ad = recoveryManager.getUnitPrefix() + "_" + EsIndex.CATEGORY_AD; if (Arrays.asList(indexList).contains(ad)) { log.warn("Cannot specify both -c and -i " + recoveryManager.getUnitPrefix() + "_ad option."); log.warn("Recovery failure"); System.exit(1); } } // ?????? try { LockUtility.lock(); } catch (AlreadyStartedException e) { log.info("Recovery has already started"); log.info("Recovery failure"); return; } catch (Exception e) { log.error("Failed to get lock for the double start control"); e.printStackTrace(); LockUtility.release(); log.error("Recovery failure"); System.exit(1); } // ?? try { recoveryManager.recovery(); } catch (Exception e) { LockUtility.release(); log.error("Recovery failure"); System.exit(1); } LockUtility.release(); log.info("Recovery Success"); return; }
From source file:org.apache.ctakes.ytex.kernel.IntrinsicInfoContentEvaluatorImpl.java
/** * @param args//from w ww . j av a 2 s .c o m * @throws IOException */ public static void main(String[] args) throws IOException { Properties props = (Properties) KernelContextHolder.getApplicationContext().getBean("ytexProperties"); props.putAll(System.getProperties()); if (!props.containsKey("org.apache.ctakes.ytex.conceptGraphName")) { System.err.println("error: org.apache.ctakes.ytex.conceptGraphName not specified"); System.exit(1); } else { IntrinsicInfoContentEvaluator corpusEvaluator = KernelContextHolder.getApplicationContext() .getBean(IntrinsicInfoContentEvaluator.class); corpusEvaluator.evaluateIntrinsicInfoContent(props); System.exit(0); } }
From source file:com.ontotext.s4.service.S4ServiceClient.java
public static void main(String... args) { if (args == null || args.length == 0) { printUsageAndTerminate(null);// w ww.j a v a 2 s.co m } Parameters params = new Parameters(args); String serviceID = params.getValue("service"); if (serviceID == null) { printUsageAndTerminate("No service name provided"); } ServiceDescriptor service = null; try { service = ServicesCatalog.getItem(serviceID); } catch (UnsupportedOperationException uoe) { printUsageAndTerminate("Unsupported service '" + serviceID + '\''); } SupportedMimeType mimetype = SupportedMimeType.PLAINTEXT; if (params.getValue("dtype") != null) { try { mimetype = SupportedMimeType.valueOf(params.getValue("dtype")); } catch (IllegalArgumentException iae) { printUsageAndTerminate("Unsupported document type (dtype) : " + params.getValue("dtype")); } } String inFile = params.getValue("file"); String url = params.getValue("url"); String outFile = params.getValue("out", "result.json"); if (inFile != null) { if (!new File(inFile).exists()) { printUsageAndTerminate("Input file is not found : " + inFile); } } else { if (url == null) { printUsageAndTerminate("Neither input file, nor remote URL provided"); } } Properties creds = readCredentials(params); if (!creds.containsKey("apikey") || !creds.containsKey("secret")) { printUsageAndTerminate("No credentials details found"); } S4ServiceClient client = new S4ServiceClient(service, creds.getProperty("apikey"), creds.getProperty("secret")); try { InputStream resultData = null; if (service.getName().equals("news-classifier")) { resultData = (inFile != null) ? client.classifyFileContentsAsStream(new File(inFile), Charset.forName("UTF-8"), mimetype) : client.classifyDocumentFromUrlAsStream(new URL(url), mimetype); } else { resultData = (inFile != null) ? client.annotateFileContentsAsStream(new File(inFile), Charset.forName("UTF-8"), mimetype, ResponseFormat.JSON) : client.annotateDocumentFromUrlAsStream(new URL(url), mimetype, ResponseFormat.JSON); } FileOutputStream outStream = new FileOutputStream(outFile); IOUtils.copy(resultData, outStream); outStream.close(); resultData.close(); } catch (IOException ioe) { System.out.println(ioe.getMessage()); System.exit(1); } }
From source file:com.simple.sftpfetch.App.java
public static void main(String[] args) throws Exception { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); Options options = getOptions();// w ww . j ava 2 s.c o m List<String> requiredProperties = asList("c"); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("h")) { printUsage(options); System.exit(0); } for (String opt : requiredProperties) { if (!commandLine.hasOption(opt)) { System.err.println("The option: " + opt + " is required."); printUsage(options); System.exit(1); } } Pattern pattern; if (commandLine.hasOption("p")) { pattern = Pattern.compile(commandLine.getOptionValue("p")); } else { pattern = MATCH_EVERYTHING; } String filename = commandLine.getOptionValue("c"); Properties properties = new Properties(); try { InputStream stream = new FileInputStream(new File(filename)); properties.load(stream); } catch (IOException ioe) { System.err.println("Unable to read properties from: " + filename); System.exit(2); } String routingKey = ""; if (commandLine.hasOption("r")) { routingKey = commandLine.getOptionValue("r"); } else if (properties.containsKey("rabbit.routingkey")) { routingKey = properties.getProperty("rabbit.routingkey"); } int daysToFetch; if (commandLine.hasOption("d")) { daysToFetch = Integer.valueOf(commandLine.getOptionValue("d")); } else { daysToFetch = Integer.valueOf(properties.getProperty(FETCH_DAYS)); } FileDecrypter decrypter = null; if (properties.containsKey("decryption.key.path")) { decrypter = new PGPFileDecrypter(new File(properties.getProperty("decryption.key.path"))); } else { decrypter = new NoopDecrypter(); } SftpClient sftpClient = new SftpClient(new JSch(), new SftpConnectionInfo(properties)); try { App app = new App(sftpClient, s3FromProperties(properties), new RabbitClient(new ConnectionFactory(), new RabbitConnectionInfo(properties)), decrypter, System.out); app.run(routingKey, daysToFetch, pattern, commandLine.hasOption("n"), commandLine.hasOption("o")); } finally { sftpClient.close(); } System.exit(0); } catch (UnrecognizedOptionException uoe) { System.err.println(uoe.getMessage()); printUsage(options); System.exit(10); } }
From source file:com.google.oacurl.Fetch.java
public static void main(String[] args) throws Exception { FetchOptions options = new FetchOptions(); CommandLine line = options.parse(args); args = line.getArgs();/*www . j a v a2 s . co m*/ if (options.isHelp()) { new HelpFormatter().printHelp("url", options.getOptions()); System.exit(0); } if (args.length != 1) { new HelpFormatter().printHelp("url", options.getOptions()); System.exit(-1); } if (options.isInsecure()) { SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier()); } LoggingConfig.init(options.isVerbose()); if (options.isVerbose()) { LoggingConfig.enableWireLog(); } String url = args[0]; ServiceProviderDao serviceProviderDao = new ServiceProviderDao(); ConsumerDao consumerDao = new ConsumerDao(); AccessorDao accessorDao = new AccessorDao(); Properties loginProperties = null; try { loginProperties = new PropertiesProvider(options.getLoginFileName()).get(); } catch (FileNotFoundException e) { System.err.println(".oacurl.properties file not found in homedir"); System.err.println("Make sure you've run oacurl-login first!"); System.exit(-1); } OAuthServiceProvider serviceProvider = serviceProviderDao.nullServiceProvider(); OAuthConsumer consumer = consumerDao.loadConsumer(loginProperties, serviceProvider); OAuthAccessor accessor = accessorDao.loadAccessor(loginProperties, consumer); OAuthClient client = new OAuthClient(new HttpClient4(SingleClient.HTTP_CLIENT_POOL)); OAuthVersion version = (loginProperties.containsKey("oauthVersion")) ? OAuthVersion.valueOf(loginProperties.getProperty("oauthVersion")) : OAuthVersion.V1; OAuthEngine engine; switch (version) { case V1: engine = new V1OAuthEngine(); break; case V2: engine = new V2OAuthEngine(); break; case WRAP: engine = new WrapOAuthEngine(); break; default: throw new IllegalArgumentException("Unknown version: " + version); } try { OAuthMessage request; List<Entry<String, String>> related = options.getRelated(); Method method = options.getMethod(); if (method == Method.POST || method == Method.PUT) { InputStream bodyStream; if (related != null) { bodyStream = new MultipartRelatedInputStream(related); } else if (options.getFile() != null) { bodyStream = new FileInputStream(options.getFile()); } else { bodyStream = System.in; } request = newRequestMessage(accessor, method, url, bodyStream, engine); request.getHeaders().add(new OAuth.Parameter("Content-Type", options.getContentType())); } else { request = newRequestMessage(accessor, method, url, null, engine); } List<Parameter> headers = options.getHeaders(); addHeadersToRequest(request, headers); HttpResponseMessage httpResponse; if (version == OAuthVersion.V1) { OAuthResponseMessage response; response = client.access(request, ParameterStyle.AUTHORIZATION_HEADER); httpResponse = response.getHttpResponse(); } else { HttpMessage httpRequest = new HttpMessage(request.method, new URL(request.URL), request.getBodyAsStream()); httpRequest.headers.addAll(request.getHeaders()); httpResponse = client.getHttpClient().execute(httpRequest, client.getHttpParameters()); httpResponse = HttpMessageDecoder.decode(httpResponse); } System.err.flush(); if (options.isInclude()) { Map<String, Object> dump = new HashMap<String, Object>(); httpResponse.dump(dump); System.out.print(dump.get(HttpMessage.RESPONSE)); } // Dump the bytes in the response's encoding. InputStream bodyStream = httpResponse.getBody(); byte[] buf = new byte[1024]; int count; while ((count = bodyStream.read(buf)) > -1) { System.out.write(buf, 0, count); } } catch (OAuthProblemException e) { OAuthUtil.printOAuthProblemException(e); } }
From source file:org.objectrepository.MessageConsumerDaemon.java
/** * main/*from w w w . j a va2s .co m*/ * <p/> * Accepts one folder as argument: -messageQueues * That folder ought to contain one or more folders ( or symbolic links ) to the files * The folder has the format: [foldername] or [foldername].[maxTasks] * MaxTasks is to indicate the total number of jobs being able to run. * * long * * @param argv */ public static void main(String[] argv) { if (instance == null) { final Properties properties = new Properties(); if (argv.length > 0) { for (int i = 0; i < argv.length; i += 2) { try { properties.put(argv[i], argv[i + 1]); } catch (ArrayIndexOutOfBoundsException arr) { System.out.println("Missing value after parameter " + argv[i]); System.exit(-1); } } } else { log.fatal("Usage: pmq-agent.jar -messageQueues [queues] -heartbeatInterval [interval in ms]\n" + "The queues is a folder that contains symbolic links to the startup scripts."); System.exit(-1); } if (log.isInfoEnabled()) { log.info("Arguments set: "); for (String key : properties.stringPropertyNames()) { log.info("'" + key + "'='" + properties.getProperty(key) + "'"); } } if (!properties.containsKey("-messageQueues")) { log.fatal("Expected case sensitive parameter: -messageQueues"); System.exit(-1); } final File messageQueues = new File((String) properties.get("-messageQueues")); if (!messageQueues.exists()) { log.fatal("Cannot find folder for messageQueues: " + messageQueues.getAbsolutePath()); System.exit(-1); } if (messageQueues.isFile()) { log.fatal( "-messageQueues should point to a folder, not a file: " + messageQueues.getAbsolutePath()); System.exit(-1); } long heartbeatInterval = 600000; if (properties.containsKey("-heartbeatInterval")) { heartbeatInterval = Long.parseLong((String) properties.get("heartbeatInterval")); } String identifier = null; if (properties.containsKey("-id")) { identifier = (String) properties.get("-id"); } else if (properties.containsKey("-identifier")) { identifier = (String) properties.get("-identifier"); } final File[] files = messageQueues.listFiles(); final String[] scriptNames = (properties.containsKey("-startup")) ? new String[] { properties.getProperty("-startup") } : new String[] { "/startup.sh", "\\startup.bat" }; final List<Queue> queues = new ArrayList<Queue>(); for (File file : files) { final String name = file.getName(); final String[] split = name.split("\\.", 2); final String queueName = split[0]; for (String scriptName : scriptNames) { final String shellScript = file.getAbsolutePath() + scriptName; final int maxTask = (split.length == 1) ? 1 : Integer.parseInt(split[1]); log.info("Candidate mq client for " + queueName + " maxTasks " + maxTask); if (new File(shellScript).exists()) { final Queue queue = new Queue(queueName, shellScript, false); queue.setCorePoolSize(1); queue.setMaxPoolSize(maxTask); queue.setQueueCapacity(1); queues.add(queue); break; } else { log.warn("... skipping, because no startup script found at " + shellScript); } } } if (queues.size() == 0) { log.fatal("No queue folders seen in " + messageQueues.getAbsolutePath()); System.exit(-1); } // Add the system queue queues.add(new Queue("Connection", null, true)); getInstance(queues, identifier, heartbeatInterval).run(); } System.exit(0); }
From source file:org.apache.ctakes.ytex.kernel.FoldGeneratorImpl.java
@SuppressWarnings("static-access") public static void main(String args[]) throws ParseException, IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("prop").hasArg() .withDescription("property file with query to retrieve instance id - label - class triples") .create("prop")); // OptionGroup group = new OptionGroup(); // group//from ww w . j a va2s.c om // .addOption(OptionBuilder // .withArgName("query") // .hasArg() // .withDescription( // "query to retrieve instance id - label - class triples") // .create("query")); // group // .addOption(OptionBuilder // .withArgName("prop") // .hasArg() // .withDescription( // "property file with query to retrieve instance id - label - class triples") // .create("prop")); // group.isRequired(); // options.addOptionGroup(group); // options.addOption(OptionBuilder.withArgName("name").hasArg() // .isRequired().withDescription("name. required").create("name")); // options.addOption(OptionBuilder.withArgName("runs").hasArg() // .withDescription("number of runs, default 1").create("runs")); // options.addOption(OptionBuilder.withArgName("folds").hasArg() // .withDescription("number of folds, default 4").create("folds")); // options.addOption(OptionBuilder.withArgName("minPerClass").hasArg() // .withDescription("minimum instances per class, default 1") // .create("minPerClass")); // options.addOption(OptionBuilder.withArgName("rand").hasArg() // .withDescription( // "random number seed; default current time in millis") // .create("rand")); try { if (args.length == 0) printHelp(options); else { CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); String propFile = line.getOptionValue("prop"); Properties props = FileUtil.loadProperties(propFile, true); // Integer rand = line.hasOption("rand") ? Integer.parseInt(line // .getOptionValue("rand")) : null; // int runs = Integer.parseInt(line.getOptionValue("runs", // "1")); // int minPerClass = Integer.parseInt(line.getOptionValue( // "minPerClass", "1")); // int folds = Integer.parseInt(line.getOptionValue("folds", // "4")); String corpusName = props.getProperty("org.apache.ctakes.ytex.corpusName"); String splitName = props.getProperty("org.apache.ctakes.ytex.splitName"); String query = props.getProperty("instanceClassQuery"); int folds = Integer.parseInt(props.getProperty("folds", "2")); int runs = Integer.parseInt(props.getProperty("runs", "5")); int minPerClass = Integer.parseInt(props.getProperty("minPerClass", "1")); Integer rand = props.containsKey("rand") ? Integer.parseInt(props.getProperty("rand")) : null; boolean argsOk = true; if (corpusName == null) { log.error("missing parameter: org.apache.ctakes.ytex.corpusName"); argsOk = false; } if (query == null) { log.error("missing parameter: instanceClassQuery"); argsOk = false; } if (!argsOk) { printHelp(options); System.exit(1); } else { KernelContextHolder.getApplicationContext().getBean(FoldGenerator.class) .generateRuns(corpusName, splitName, query, folds, minPerClass, rand, runs); } } } catch (ParseException pe) { printHelp(options); } }
From source file:io.anserini.index.UserPostFrequencyDistribution.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors")); options.addOption(OptionBuilder.withArgName("collection").hasArg() .withDescription("source collection directory").create(COLLECTION_OPTION)); options.addOption(OptionBuilder.withArgName("property").hasArg() .withDescription("source collection directory").create("property")); options.addOption(OptionBuilder.withArgName("collection_pattern").hasArg() .withDescription("source collection directory").create("collection_pattern")); CommandLine cmdline = null;//from w w w . ja v a 2 s .c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(COLLECTION_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(UserPostFrequencyDistribution.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); final FieldType textOptions = new FieldType(); textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); textOptions.setStored(true); textOptions.setTokenized(true); textOptions.setStoreTermVectors(true); LOG.info("collection: " + collectionPath); LOG.info("collection_pattern " + cmdline.getOptionValue("collection_pattern")); LOG.info("property " + cmdline.getOptionValue("property")); LongOpenHashSet deletes = null; long startTime = System.currentTimeMillis(); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } final JsonStatusCorpusReader stream = new JsonStatusCorpusReader(file, cmdline.getOptionValue("collection_pattern")); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { stream.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ; System.out.println("# of users indexed this round: " + userIndexedCount); System.out.println("Shutting down"); } }); Status status; boolean readerNotInitialized = true; try { Properties prop = new Properties(); while ((status = stream.next()) != null) { // try{ // status = DataObjectFactory.createStatus(s); // if (status==null||status.getText() == null) { // continue; // }}catch(Exception e){ // // } // boolean pittsburghRelated = false; try { if (Math.abs(status.getLongitude() - pittsburghLongitude) < 0.05d && Math.abs(status.getlatitude() - pittsburghLatitude) < 0.05d) pittsburghRelated = true; } catch (Exception e) { } try { if (status.getPlace().contains("Pittsburgh, PA")) pittsburghRelated = true; } catch (Exception e) { } try { if (status.getUserLocation().contains("Pittsburgh, PA")) pittsburghRelated = true; } catch (Exception e) { } try { if (status.getText().contains("Pittsburgh")) pittsburghRelated = true; } catch (Exception e) { } if (pittsburghRelated) { int previousPostCount = 0; if (prop.containsKey(String.valueOf(status.getUserid()))) { previousPostCount = Integer .valueOf(prop.getProperty(String.valueOf(status.getUserid())).split(" ")[1]); } prop.setProperty(String.valueOf(status.getUserid()), String.valueOf(status.getStatusesCount()) + " " + (1 + previousPostCount)); if (prop.size() > 0 && prop.size() % 1000 == 0) { Runtime runtime = Runtime.getRuntime(); runtime.gc(); System.out.println("Property size " + prop.size() + "Memory used: " + ((runtime.totalMemory() - runtime.freeMemory()) / (1024L * 1024L)) + " MB\n"); } OutputStream output = new FileOutputStream(cmdline.getOptionValue("property"), false); prop.store(output, null); output.close(); } } // prop.store(output, null); LOG.info(String.format("Total of %s statuses added", userIndexedCount)); LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms"); } catch (Exception e) { e.printStackTrace(); } finally { stream.close(); } }
From source file:Main.java
/** * Gets the boolean property from the properties object. * @param key the key of the boolean property * @param defaultValue the default value if the property doesn't exist * @param properties the properties object to get the property from * @return the property value, defaultValue if the property doesn't exist *//*w ww . ja va 2 s .c o m*/ public static boolean getBoolean(String key, boolean defaultValue, Properties properties) { if (properties.containsKey(key)) { return Boolean.valueOf(properties.getProperty(key, "false")); } else { return defaultValue; } }