List of usage examples for java.io File isDirectory
public boolean isDirectory()
From source file:com.tamingtext.qa.WikipediaIndexer.java
public static void main(String[] args) throws Exception { DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); ArgumentBuilder abuilder = new ArgumentBuilder(); GroupBuilder gbuilder = new GroupBuilder(); Option wikipediaFileOpt = obuilder.withLongName("wikiFile").withRequired(true) .withArgument(abuilder.withName("wikiFile").withMinimum(1).withMaximum(1).create()) .withDescription(// w w w . j a va 2 s. c o m "The path to the wikipedia dump file. Maybe a directory containing wikipedia dump files." + " If a directory is specified, only .xml files are used.") .withShortName("w").create(); Option numDocsOpt = obuilder.withLongName("numDocs").withRequired(false) .withArgument(abuilder.withName("numDocs").withMinimum(1).withMaximum(1).create()) .withDescription("The number of docs to index").withShortName("n").create(); Option solrURLOpt = obuilder.withLongName("solrURL").withRequired(false) .withArgument(abuilder.withName("solrURL").withMinimum(1).withMaximum(1).create()) .withDescription("The URL where Solr lives").withShortName("s").create(); Option solrBatchOpt = obuilder.withLongName("batch").withRequired(false) .withArgument(abuilder.withName("batch").withMinimum(1).withMaximum(1).create()) .withDescription("The number of docs to include in each indexing batch").withShortName("b") .create(); Group group = gbuilder.withName("Options").withOption(wikipediaFileOpt).withOption(numDocsOpt) .withOption(solrURLOpt).withOption(solrBatchOpt).create(); Parser parser = new Parser(); parser.setGroup(group); CommandLine cmdLine = parser.parse(args); File file; file = new File(cmdLine.getValue(wikipediaFileOpt).toString()); File[] dumpFiles; if (file.isDirectory()) { dumpFiles = file.listFiles(new FilenameFilter() { public boolean accept(File file, String s) { return s.endsWith(".xml"); } }); } else { dumpFiles = new File[] { file }; } int numDocs = Integer.MAX_VALUE; if (cmdLine.hasOption(numDocsOpt)) { numDocs = Integer.parseInt(cmdLine.getValue(numDocsOpt).toString()); } String url = DEFAULT_SOLR_URL; if (cmdLine.hasOption(solrURLOpt)) { url = cmdLine.getValue(solrURLOpt).toString(); } int batch = 100; if (cmdLine.hasOption(solrBatchOpt)) { batch = Integer.parseInt(cmdLine.getValue(solrBatchOpt).toString()); } WikipediaIndexer indexer = new WikipediaIndexer(new CommonsHttpSolrServer(url)); int total = 0; for (int i = 0; i < dumpFiles.length && total < numDocs; i++) { File dumpFile = dumpFiles[i]; log.info("Indexing: " + file + " Num files to index: " + (numDocs - total)); long start = System.currentTimeMillis(); int totalFile = indexer.index(dumpFile, numDocs - total, batch); long finish = System.currentTimeMillis(); if (log.isInfoEnabled()) { log.info("Indexing " + dumpFile + " took " + (finish - start) + " ms"); } total += totalFile; log.info("Done Indexing: " + file + ". Indexed " + totalFile + " docs for that file and " + total + " overall."); } log.info("Indexed " + total + " docs overall."); }
From source file:me.crime.loader.DataBaseLoader.java
/** * @param args/*from ww w . j av a 2s .c o m*/ * @throws ClassNotFoundException * @throws SQLException */ public static void main(String[] args) { DaoBeanFactory.initilize(); DataBaseLoader loader = new DataBaseLoader(); try { loader.loadURCTable(); } catch (SQLException e) { log_.error(e); } catch (ClassNotFoundException e) { log_.error(e); } int total = 0; for (String s : args) { try { System.out.println("loading " + s + "... "); File fp = new File(s); if (fp.isDirectory()) { total = loader.parseDir(fp); } else { total = loader.parse(s); } System.out.println(s + " done, saved:" + total); } catch (Exception ex) { log_.error(ex); } catch (java.lang.Error ex) { log_.error(ex); } } }
From source file:com.codename1.tools.javadoc.sourceembed.javadocsourceembed.Main.java
public static void main(String[] args) throws Exception { // this accepts two arguments source directory and destination directory where the modfied files will // be written File sourceDir = new File(args[0]); File destDir = new File(args[1]); System.out//from w ww . j a v a 2 s .co m .println("JavaDoc conversion " + sourceDir.getAbsolutePath() + " to " + destDir.getAbsolutePath()); if (!sourceDir.exists() || !sourceDir.isDirectory()) { System.out.println("Source directory doesn't exist"); System.exit(1); return; } CHARSET = Charset.forName("UTF-8"); directoryWalker(sourceDir, destDir); }
From source file:gr.csri.poeticon.praxicon.CreateNeo4JDB.java
public static void main(final String[] args) { if (args.length > 0) { if (args[0] != null && args[0].length() > 0) { File f = new File(args[0]); if (f.exists() && f.isDirectory()) { DB_PATH = args[0];/*from w w w . ja v a 2s .c om*/ } } } CreateNeo4JDB myNeoInstance = new CreateNeo4JDB(); myNeoInstance.dropDb(); myNeoInstance.createGraph(); myNeoInstance.shutDown(); System.exit(0); }
From source file:com.act.lcms.db.analysis.FeedingAnalysis.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//from www. j ava 2 s . c om } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } File lcmsDir = new File(cl.getOptionValue(OPTION_DIRECTORY)); if (!lcmsDir.isDirectory()) { System.err.format("File at %s is not a directory\n", lcmsDir.getAbsolutePath()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } try (DB db = DB.openDBFromCLI(cl)) { System.out.format("Loading/updating LCMS scan files into DB\n"); ScanFile.insertOrUpdateScanFilesInDirectory(db, lcmsDir); System.out.format("Running feeding analysis\n"); performFeedingAnalysis(db, cl.getOptionValue(OPTION_DIRECTORY), cl.getOptionValue(OPTION_ION_NAME), cl.getOptionValue(OPTION_SEARCH_MZ), cl.getOptionValue(OPTION_PLATE_BARCODE), cl.getOptionValue(OPTION_FEEDING_STRAIN_OR_CONSTRUCT), cl.getOptionValue(OPTION_FEEDING_EXTRACT), cl.getOptionValue(OPTION_FEEDING_FED_CHEMICAL), cl.getOptionValue(OPTION_OUTPUT_PREFIX), "pdf"); } }
From source file:com.opensearchserver.affinities.Main.java
public static void main(String[] args) throws IOException, ParseException { Logger.getLogger("").setLevel(Level.WARNING); Options options = new Options(); options.addOption("h", "help", false, "print this message"); options.addOption("d", "datadir", true, "Data directory"); options.addOption("p", "port", true, "TCP port"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar target/oss-affinities.jar", options); return;//from ww w. j a v a2 s .com } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9092; File dataDir = new File(System.getProperty("user.home"), "opensearchserver_affinities"); if (cmd.hasOption("d")) dataDir = new File(cmd.getOptionValue("d")); if (!dataDir.exists()) throw new IOException("The data directory does not exists: " + dataDir); if (!dataDir.isDirectory()) throw new IOException("The data directory path is not a directory: " + dataDir); AffinityList.load(dataDir); UndertowJaxrsServer server = new UndertowJaxrsServer() .start(Undertow.builder().addHttpListener(port, "0.0.0.0")); server.deploy(Main.class); }
From source file:com.jbrisbin.groovy.mqdsl.RabbitMQDsl.java
public static void main(String[] argv) { // Parse command line arguments CommandLine args = null;// w ww . j ava 2 s .c o m try { Parser p = new BasicParser(); args = p.parse(cliOpts, argv); } catch (ParseException e) { log.error(e.getMessage(), e); } // Check for help if (args.hasOption('?')) { printUsage(); return; } // Runtime properties Properties props = System.getProperties(); // Check for ~/.rabbitmqrc File userSettings = new File(System.getProperty("user.home"), ".rabbitmqrc"); if (userSettings.exists()) { try { props.load(new FileInputStream(userSettings)); } catch (IOException e) { log.error(e.getMessage(), e); } } // Load Groovy builder file StringBuffer script = new StringBuffer(); BufferedInputStream in = null; String filename = "<STDIN>"; if (args.hasOption("f")) { filename = args.getOptionValue("f"); try { in = new BufferedInputStream(new FileInputStream(filename)); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } } else { in = new BufferedInputStream(System.in); } // Read script if (null != in) { byte[] buff = new byte[4096]; try { for (int read = in.read(buff); read > -1;) { script.append(new String(buff, 0, read)); read = in.read(buff); } } catch (IOException e) { log.error(e.getMessage(), e); } } else { System.err.println("No script file to evaluate..."); } PrintStream stdout = System.out; PrintStream out = null; if (args.hasOption("o")) { try { out = new PrintStream(new FileOutputStream(args.getOptionValue("o")), true); System.setOut(out); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } } String[] includes = (System.getenv().containsKey("MQDSL_INCLUDE") ? System.getenv("MQDSL_INCLUDE").split(String.valueOf(File.pathSeparatorChar)) : new String[] { System.getenv("HOME") + File.separator + ".mqdsl.d" }); try { // Setup RabbitMQ String username = (args.hasOption("U") ? args.getOptionValue("U") : props.getProperty("mq.user", "guest")); String password = (args.hasOption("P") ? args.getOptionValue("P") : props.getProperty("mq.password", "guest")); String virtualHost = (args.hasOption("v") ? args.getOptionValue("v") : props.getProperty("mq.virtualhost", "/")); String host = (args.hasOption("h") ? args.getOptionValue("h") : props.getProperty("mq.host", "localhost")); int port = Integer.parseInt( args.hasOption("p") ? args.getOptionValue("p") : props.getProperty("mq.port", "5672")); CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host); connectionFactory.setPort(port); connectionFactory.setUsername(username); connectionFactory.setPassword(password); if (null != virtualHost) { connectionFactory.setVirtualHost(virtualHost); } // The DSL builder RabbitMQBuilder builder = new RabbitMQBuilder(); builder.setConnectionFactory(connectionFactory); // Our execution environment Binding binding = new Binding(args.getArgs()); binding.setVariable("mq", builder); String fileBaseName = filename.replaceAll("\\.groovy$", ""); binding.setVariable("log", LoggerFactory.getLogger(fileBaseName.substring(fileBaseName.lastIndexOf("/") + 1))); if (null != out) { binding.setVariable("out", out); } // Include helper files GroovyShell shell = new GroovyShell(binding); for (String inc : includes) { File f = new File(inc); if (f.isDirectory()) { File[] files = f.listFiles(new FilenameFilter() { @Override public boolean accept(File file, String s) { return s.endsWith(".groovy"); } }); for (File incFile : files) { run(incFile, shell, binding); } } else { run(f, shell, binding); } } run(script.toString(), shell, binding); while (builder.isActive()) { try { Thread.sleep(500); } catch (InterruptedException e) { log.error(e.getMessage(), e); } } if (null != out) { out.close(); System.setOut(stdout); } } finally { System.exit(0); } }
From source file:licenseUtil.LicenseUtil.java
public static void main(String[] args) throws IOException, IncompleteLicenseObjectException { if (args.length == 0) { logger.error("Missing parameters. Use --help to get a list of the possible options."); } else if (args[0].equals("--addPomToTsv")) { if (args.length < 4) logger.error(/*from ww w . j ava 2s. c om*/ "Missing arguments for option --addPomToTsv. Please specify <pomFileName> <licenses.stub.tsv> <currentVersion> or use the option --help for further information."); String pomFN = args[1]; String spreadSheetFN = args[2]; String currentVersion = args[3]; MavenProject project = null; try { project = Utils.readPom(new File(pomFN)); } catch (XmlPullParserException e) { logger.error("Could not parse pom file: \"" + pomFN + "\""); } LicensingList licensingList = new LicensingList(); File f = new File(spreadSheetFN); if (f.exists() && !f.isDirectory()) { licensingList.readFromSpreadsheet(spreadSheetFN); } licensingList.addMavenProject(project, currentVersion); licensingList.writeToSpreadsheet(spreadSheetFN); } else if (args[0].equals("--writeLicense3rdParty")) { if (args.length < 4) logger.error( "Missing arguments for option --writeLicense3rdParty. Please provide <licenses.enhanced.tsv> <processModule> <currentVersion> [and <targetDir>] or use the option --help for further information."); String spreadSheetFN = args[1]; String processModule = args[2]; String currentVersion = args[3]; HashMap<String, String> targetDirs = new HashMap<>(); if (args.length > 4) { File targetDir = new File(args[4]); logger.info("scan pom files in direct subdirectories of \"" + targetDir.getPath() + "\" to obtain target locations for 3rd party license files..."); File[] subdirs = targetDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY); for (File subdir : subdirs) { File pomFile = new File(subdir.getPath() + File.separator + POM_FN); if (!pomFile.exists()) continue; MavenProject mavenProject; try { mavenProject = Utils.readPom(pomFile); } catch (Exception e) { logger.warn("Could not read from pom file: \"" + pomFile.getPath() + "\" because of " + e.getMessage()); continue; } targetDirs.put(mavenProject.getModel().getArtifactId(), subdir.getAbsolutePath()); } } LicensingList licensingList = new LicensingList(); licensingList.readFromSpreadsheet(spreadSheetFN); if (processModule.toUpperCase().equals("ALL")) { for (String module : licensingList.getNonFixedHeaders()) { try { writeLicense3rdPartyFile(module, licensingList, currentVersion, targetDirs.get(module)); } catch (NoLicenseTemplateSetException e) { logger.error("Could not write file for module \"" + module + "\". There is no template specified for \"" + e.getLicensingObject() + "\". Please add an existing template filename to the column \"" + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN + "\"."); } } } else { try { writeLicense3rdPartyFile(processModule, licensingList, currentVersion, targetDirs.get(processModule)); } catch (NoLicenseTemplateSetException e) { logger.error("Could not write file for module \"" + processModule + "\". There is no template specified for \"" + e.getLicensingObject() + "\". Please add an existing template filename to the column \"" + LicensingObject.ColumnHeader.LICENSE_TEMPLATE.value() + "\" of \"" + spreadSheetFN + "\"."); } } } else if (args[0].equals("--buildEffectivePom")) { Utils.writeEffectivePom(new File(args[1]), (new File(EFFECTIVE_POM_FN)).getAbsolutePath()); } else if (args[0].equals("--updateTsvWithProjectsInFolder")) { if (args.length < 4) logger.error( "Missing arguments for option --processProjectsInFolder. Please provide <superDirectory> <licenses.stub.tsv> and <currentVersion> or use the option --help for further information."); File directory = new File(args[1]); String spreadSheetFN = args[2]; String currentVersion = args[3]; LicensingList licensingList = new LicensingList(); File f = new File(spreadSheetFN); if (f.exists() && !f.isDirectory()) { licensingList.readFromSpreadsheet(spreadSheetFN); } licensingList.addAll(processProjectsInFolder(directory, currentVersion, false)); licensingList.writeToSpreadsheet(spreadSheetFN); } else if (args[0].equals("--purgeTsv")) { if (args.length < 3) logger.error( "Missing arguments for option --purgeTsv. Please provide <spreadSheetIN.tsv>, <spreadSheetOUT.tsv> and <currentVersion> or use the option --help for further information."); String spreadSheetIN = args[1]; String spreadSheetOUT = args[2]; String currentVersion = args[3]; LicensingList licensingList = new LicensingList(); licensingList.readFromSpreadsheet(spreadSheetIN); licensingList.purge(currentVersion); licensingList.writeToSpreadsheet(spreadSheetOUT); } else if (args[0].equals("--help")) { InputStream in = LicenseUtil.class.getClassLoader().getResourceAsStream(README_PATH); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } else { logger.error("Unknown parameter: " + args[0] + ". Use --help to get a list of the possible options."); } }
From source file:com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Usage: $0 <table directory with segments>"); System.exit(1);//from w w w .jav a 2 s . c om } File tableDirectory = new File(args[0]); Preconditions.checkState(tableDirectory.exists(), "Directory: {} does not exist", tableDirectory); Preconditions.checkState(tableDirectory.isDirectory(), "Path: {} is not a directory", tableDirectory); File[] files = tableDirectory.listFiles(); SegmentFormatConverter converter = new SegmentV1V2ToV3FormatConverter(); for (File file : files) { if (!file.isDirectory()) { System.out.println("Path: " + file + " is not a directory. Skipping..."); continue; } long startTimeNano = System.nanoTime(); converter.convert(file); long endTimeNano = System.nanoTime(); long latency = (endTimeNano - startTimeNano) / (1000 * 1000); System.out.println("Converting segment: " + file + " took " + latency + " milliseconds"); } }
From source file:de.hpi.fgis.hdrs.tools.Loader.java
public static void main(String[] args) throws IOException { if (2 > args.length) { System.out.println(usage); System.out.println(options); System.exit(1);//from www . j a v a 2 s . c o m } if (0 > args[0].indexOf(':')) { args[0] += ":" + Configuration.DEFAULT_RPC_PORT; } Configuration conf = Configuration.create(); Client client = new Client(conf, args[0]); File[] files; String options = ""; if (args[1].startsWith("-")) { options = args[1]; if (3 > args.length) { System.out.println(usage); System.exit(1); } if (0 < options.indexOf('d')) { File dir = new File(args[2]); if (!dir.isDirectory()) { throw new IOException("Directory does not exist."); } files = dir.listFiles(); } else { files = new File[] { new File(args[2]) }; } } else { files = new File[] { new File(args[1]) }; } boolean quiet = 0 < options.indexOf('q'); boolean context = 0 < options.indexOf('c'); boolean bench = 0 < options.indexOf('b'); List<BenchSample> benchSamples = null; if (bench) { benchSamples = new ArrayList<BenchSample>(); } long timeStalled = 0; long timeRouterUpdate = 0; long abortedTransactions = 0; long nBytesTotal = 0; long nTriplesTotal = 0; long timeTotal = 0; for (int i = 0; i < files.length; ++i) { Closeable source = null; TripleScanner scanner = null; try { if (0 < options.indexOf('t')) { TripleFileReader reader = new TripleFileReader(files[i]); reader.open(); scanner = reader.getScanner(); source = reader; } else if (0 < options.indexOf('z')) { GZIPInputStream stream = new GZIPInputStream(new FileInputStream(files[i])); BTCParser parser = new BTCParser(); parser.setSkipContext(!context); scanner = new StreamScanner(stream, parser); source = stream; } else { BTCParser parser = new BTCParser(); parser.setSkipContext(!context); FileSource file = new FileSource(files[i], parser); scanner = file.getScanner(); source = file; } } catch (IOException ioe) { System.out.println("Error: Couldn't open " + files[i] + ". See log for details."); LOG.error("Error: Couldn't open " + files[i] + ":", ioe); continue; } long nBytes = 0; long nTriples = 0; long time = System.currentTimeMillis(); TripleOutputStream out = client.getOutputStream(); while (scanner.next()) { Triple t = scanner.pop(); out.add(t); nBytes += t.serializedSize(); nTriples++; if (!quiet && 0 == (nTriples % (16 * 1024))) { System.out.print(String.format("\rloading... %d triples (%.2f MB, %.2f MB/s)", nTriples, LogFormatUtil.MB(nBytes), LogFormatUtil.MBperSec(nBytes, System.currentTimeMillis() - time))); } } out.close(); time = System.currentTimeMillis() - time; scanner.close(); source.close(); if (!quiet) { System.out.print("\r"); } System.out.println(String.format("%s: %d triples (%.2f MB) loaded " + "in %.2f seconds (%.2f MB/s)", files[i], nTriples, LogFormatUtil.MB(nBytes), time / 1000.0, LogFormatUtil.MBperSec(nBytes, time))); nBytesTotal += nBytes; nTriplesTotal += nTriples; timeTotal += time; timeStalled += out.getTimeStalled(); timeRouterUpdate += out.getTimeRouterUpdate(); abortedTransactions += out.getAbortedTransactions(); if (bench) { benchSamples.add(new BenchSample(time, nTriples, nBytes)); } } client.close(); if (0 == nTriplesTotal) { System.out.println("No triples loaded."); return; } System.out.println( String.format("Done loading. Totals: %d triples (%.2f MB) loaded " + "in %.2f seconds (%.2f MB/s)", nTriplesTotal, LogFormatUtil.MB(nBytesTotal), timeTotal / 1000.0, LogFormatUtil.MBperSec(nBytesTotal, timeTotal))); System.out.println(String.format( " Client stats. Stalled: %.2f s RouterUpdate: %.2f s" + " AbortedTransactions: %d", timeStalled / 1000.0, timeRouterUpdate / 1000.0, abortedTransactions)); if (bench) { System.out.println(); System.out.println("Benchmark Samples:"); System.out.println("time\tsum T\tsum MB\tMB/s"); System.out.println(String.format("%.2f\t%d\t%.2f\t%.2f", 0f, 0, 0f, 0f)); long time = 0, nTriples = 0, nBytes = 0; for (BenchSample sample : benchSamples) { time += sample.time; nTriples += sample.nTriples; nBytes += sample.nBytes; System.out.println(String.format("%.2f\t%d\t%.2f\t%.2f", time / 1000.0, nTriples, LogFormatUtil.MB(nBytes), LogFormatUtil.MBperSec(sample.nBytes, sample.time))); } } }