List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:com.linkedin.pinot.perf.BitmapPerformanceBenchmark.java
public static void main(String[] args) throws Exception { File indexDir = new File("/home/kgopalak/pinot_perf/index_dir/scinPricing_OFFLINE"); File[] segmentDirs = indexDir.listFiles(); for (File indexSegmentDir : segmentDirs) { iterationSpeed(indexSegmentDir.getAbsolutePath(), "dimension_geo"); }// w w w . j ava 2 s . c om }
From source file:org.eclipse.swt.snippets.SnippetLauncher.java
public static void main(String[] args) { File sourceDir = SnippetsConfig.SNIPPETS_SOURCE_DIR; boolean hasSource = sourceDir.exists(); int count = 500; if (hasSource) { File[] files = sourceDir.listFiles(); if (files.length > 0) count = files.length;// ww w.ja v a 2 s .c om } for (int i = 1; i < count; i++) { if (SnippetsConfig.isPrintingSnippet(i)) continue; // avoid printing to printer String className = "Snippet" + i; Class<?> clazz = null; try { clazz = Class.forName(SnippetsConfig.SNIPPETS_PACKAGE + "." + className); } catch (ClassNotFoundException e) { } if (clazz != null) { System.out.println("\n" + clazz.getName()); if (hasSource) { File sourceFile = new File(sourceDir, className + ".java"); try (FileReader reader = new FileReader(sourceFile);) { char[] buffer = new char[(int) sourceFile.length()]; reader.read(buffer); String source = String.valueOf(buffer); int start = source.indexOf("package"); start = source.indexOf("/*", start); int end = source.indexOf("* For a list of all"); System.out.println(source.substring(start, end - 3)); boolean skip = false; String platform = SWT.getPlatform(); if (source.contains("PocketPC")) { platform = "PocketPC"; skip = true; } else if (source.contains("OpenGL")) { platform = "OpenGL"; skip = true; } else if (source.contains("JavaXPCOM")) { platform = "JavaXPCOM"; skip = true; } else { String[] platforms = { "win32", "gtk" }; for (int p = 0; p < platforms.length; p++) { if (!platforms[p].equals(platform) && source.contains("." + platforms[p])) { platform = platforms[p]; skip = true; break; } } } if (skip) { System.out.println("...skipping " + platform + " example..."); continue; } } catch (Exception e) { } } Method method = null; String[] param = SnippetsConfig.getSnippetArguments(i); try { method = clazz.getMethod("main", param.getClass()); } catch (NoSuchMethodException e) { System.out.println(" Did not find main(String [])"); } if (method != null) { try { method.invoke(clazz, new Object[] { param }); } catch (IllegalAccessException e) { System.out.println(" Failed to launch (illegal access)"); } catch (IllegalArgumentException e) { System.out.println(" Failed to launch (illegal argument to main)"); } catch (InvocationTargetException e) { System.out.println(" Exception in Snippet: " + e.getTargetException()); } } } } }
From source file:SystemFileTree.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); RGB color = shell.getBackground().getRGB(); Label separator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); Label locationLb = new Label(shell, SWT.NONE); locationLb.setText("Location:"); Composite locationComp = new Composite(shell, SWT.EMBEDDED); Label separator2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); final Composite comp = new Composite(shell, SWT.NONE); final Tree fileTree = new Tree(comp, SWT.SINGLE | SWT.BORDER); Sash sash = new Sash(comp, SWT.VERTICAL); Composite tableComp = new Composite(comp, SWT.EMBEDDED); Label separator3 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); Composite statusComp = new Composite(shell, SWT.EMBEDDED); java.awt.Frame locationFrame = SWT_AWT.new_Frame(locationComp); final java.awt.TextField locationText = new java.awt.TextField(); locationFrame.add(locationText);//from w w w . j a va2s . com java.awt.Frame statusFrame = SWT_AWT.new_Frame(statusComp); statusFrame.setBackground(new java.awt.Color(color.red, color.green, color.blue)); final java.awt.Label statusLabel = new java.awt.Label(); statusFrame.add(statusLabel); statusLabel.setText("Select a file"); sash.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { if (e.detail == SWT.DRAG) return; GridData data = (GridData) fileTree.getLayoutData(); Rectangle trim = fileTree.computeTrim(0, 0, 0, 0); data.widthHint = e.x - trim.width; comp.layout(); } }); File[] roots = File.listRoots(); for (int i = 0; i < roots.length; i++) { File file = roots[i]; TreeItem treeItem = new TreeItem(fileTree, SWT.NONE); treeItem.setText(file.getAbsolutePath()); treeItem.setData(file); new TreeItem(treeItem, SWT.NONE); } fileTree.addListener(SWT.Expand, new Listener() { public void handleEvent(Event e) { TreeItem item = (TreeItem) e.item; if (item == null) return; if (item.getItemCount() == 1) { TreeItem firstItem = item.getItems()[0]; if (firstItem.getData() != null) return; firstItem.dispose(); } else { return; } File root = (File) item.getData(); File[] files = root.listFiles(); if (files == null) return; for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) { TreeItem treeItem = new TreeItem(item, SWT.NONE); treeItem.setText(file.getName()); treeItem.setData(file); new TreeItem(treeItem, SWT.NONE); } } } }); fileTree.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { TreeItem item = (TreeItem) e.item; if (item == null) return; final File root = (File) item.getData(); statusLabel.setText(root.getAbsolutePath()); locationText.setText(root.getAbsolutePath()); } }); GridLayout layout = new GridLayout(4, false); layout.marginWidth = layout.marginHeight = 0; layout.horizontalSpacing = layout.verticalSpacing = 1; shell.setLayout(layout); GridData data; data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; separator1.setLayoutData(data); data = new GridData(); data.horizontalSpan = 1; data.horizontalIndent = 10; locationLb.setLayoutData(data); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; data.heightHint = locationText.getPreferredSize().height; locationComp.setLayoutData(data); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 1; data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; separator2.setLayoutData(data); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 4; comp.setLayoutData(data); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; separator3.setLayoutData(data); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 4; data.heightHint = statusLabel.getPreferredSize().height; statusComp.setLayoutData(data); layout = new GridLayout(3, false); layout.marginWidth = layout.marginHeight = 0; layout.horizontalSpacing = layout.verticalSpacing = 1; comp.setLayout(layout); data = new GridData(GridData.FILL_VERTICAL); data.widthHint = 200; fileTree.setLayoutData(data); data = new GridData(GridData.FILL_VERTICAL); sash.setLayoutData(data); data = new GridData(GridData.FILL_BOTH); tableComp.setLayoutData(data); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:edu.illinois.cs.cogcomp.nlp.tokenizer.HashCollisionReport.java
/** * Read each test file in the directory, tokenize and create the token view. Then check for * collisions.//from w ww. j a v a 2 s . c o m * @param args * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length == 0) error("Must pass in the name of a directory with files to test against."); File dir = new File(args[0]); if (!dir.exists()) { error("The directory did not exist : " + dir); } if (!dir.isDirectory()) { error("The path was not a directory : " + dir); } File[] files = dir.listFiles(); for (File file : files) { if (file.isFile()) { String normal = FileUtils.readFileToString(file); TextAnnotationBuilder tabldr = new TokenizerTextAnnotationBuilder(new StatefulTokenizer()); TextAnnotation taNormal = tabldr.createTextAnnotation("test", "normal", normal); List<Constituent> normalToks = taNormal.getView(ViewNames.TOKENS).getConstituents(); HashMap<Integer, Constituent> hashmap = new HashMap<>(); // add each constituent to the map keyed by it's hashcode. Check first to see if the hashcode // is already used, if it is report it. for (Constituent c : normalToks) { int code = c.hashCode(); if (hashmap.containsKey(code)) { Constituent dup = hashmap.get(code); System.err.println(c + " == " + dup); } else { hashmap.put(code, c); } } } } }
From source file:com.sustainalytics.crawlerfilter.PDFtoTextBatch.java
/** * Driver method for the class/*www . j ava 2 s . c o m*/ * @param args contains the file path and name */ public static void main(String[] args) { showBanner(); File folder = new File(args[0]); // initiateLogger(folder); File[] listOfFiles = folder.listFiles(); int parserChoice = Integer.parseInt(args[1]); String content = null; for (int i = 0; i < listOfFiles.length; i++) { if (parserChoice == 1) { content = extractPDFText(listOfFiles[i].getAbsoluteFile()); } else if (parserChoice == 2) { content = extractFoxitText(listOfFiles[i].getAbsolutePath()); } else if (parserChoice == 3) { content = extractPDFExtremeText(listOfFiles[i].getAbsolutePath()); } else if (parserChoice == 4) { content = extractITextText(listOfFiles[i].getAbsolutePath()); } else if (parserChoice == 5) { content = extractTikaText(listOfFiles[i].getAbsolutePath()); } writeParsedFile(listOfFiles[i].getAbsolutePath(), content); try { FileUtils.forceDelete(listOfFiles[i].getAbsoluteFile()); } catch (IOException e) { System.out.println("Failed to delete file"); } } }
From source file:edu.illinois.cs.cogcomp.ner.BenchmarkOutputParser.java
/** * This main method will take one required argument, idenfitying the file containing * the results. Optionally, "-single" may also be passed indicating it will extract * the F1 value for single token values only. * @param args// w w w.j ava 2 s . co m * @throws IOException */ public static void main(String[] args) throws IOException { parseArgs(args); System.out.println("L1lr,L1t,L2lr,L2t,L1 token,L2 token,F1,F2"); for (File file : resultsfile.listFiles()) { if (file.getName().startsWith("L1r")) { File resultsfile = new File(file, "ner/results.out"); if (resultsfile.exists()) { try { Parameters p = parseFilename(file); String lines = FileUtils.readFileToString(resultsfile); // get the token level score. String tokenL2 = null, tokenL1 = null; Matcher matcher = l2tokenlevelpattern.matcher(lines); if (matcher.find()) tokenL2 = matcher.group(1); else { matcher = ol2tokenlevelpattern.matcher(lines); if (matcher.find()) tokenL2 = matcher.group(1); else System.err.println("No token level match"); } matcher = l1tokenlevelpattern.matcher(lines); if (matcher.find()) tokenL1 = matcher.group(1); else { matcher = ol1tokenlevelpattern.matcher(lines); if (matcher.find()) tokenL1 = matcher.group(1); else System.err.println("No token level match"); } matcher = phraselevelpattern.matcher(lines); matcher.find(); String phraseL1 = matcher.group(1); String phraseL2 = matcher.group(2); System.out.println( p.toString() + "," + tokenL1 + "," + tokenL2 + "," + phraseL1 + "," + phraseL2); } catch (java.lang.IllegalStateException ise) { System.err.println("The results file could not be parsed : \"" + resultsfile + "\""); } } else { System.err.println("no results in " + resultsfile); } } } }
From source file:jeplus.util.LineEnds.java
public static void main(String[] args) { String LN = "\r\n"; // create the parser CommandLineParser parser = new GnuParser(); Options options = getCommandLineOptions(); CommandLine commandline = null;// w w w . j av a 2 s . c o m HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(80); try { // parse the command line arguments commandline = parser.parse(options, args); if (commandline.hasOption("help")) { // automatically generate the help statement formatter.printHelp("java -cp jEPlusNet.jar jeplusplus.util.LineEnds [OPTIONS]", options); System.exit(-1); } // Set log4j configuration if (commandline.hasOption("log")) { PropertyConfigurator.configure(commandline.getOptionValue("log")); } else { PropertyConfigurator.configure("log4j.cfg"); } } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); // automatically generate the help statement formatter.printHelp("java -Xmx500m -jar JESS_Client.jar [OPTIONS]", options); System.exit(-1); } if (commandline.hasOption("style")) { if (commandline.getOptionValue("style").startsWith("L")) { LN = "\n"; } } if (commandline.hasOption("file")) { File file = new File(commandline.getOptionValue("file")); if (file.exists()) { if (file.isDirectory()) { File[] listOfFiles = file.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { convertFile(listOfFiles[i], LN); } } } else { convertFile(file, LN); } } } }
From source file:edu.cuhk.hccl.SequenceFileWriter.java
public static void main(String[] args) throws IOException { // Check parameters if (args.length < 3) { System.out.print("Please specify three parameters!"); System.exit(-1);//from w ww. ja v a2 s . co m } File filesDir = new File(args[0]); String targetDir = args[1]; final int NUM_SPLITS = Integer.parseInt(args[2]); // Remove old target directory first FileUtils.deleteQuietly(new File(targetDir)); File[] dataFiles = filesDir.listFiles(); int total = dataFiles.length; int range = (int) Math.round(total / NUM_SPLITS + 0.5); System.out.printf("[INFO] The number of total files is %d \n.", total); for (int i = 1; i <= NUM_SPLITS; i++) { int start = (i - 1) * range; int end = Math.min(start + range, total); File[] subFiles = Arrays.copyOfRange(dataFiles, start, end); createSeqFile(subFiles, FilenameUtils.normalize(targetDir + "/" + i + ".seq")); } System.out.println("[INFO] All files have been successfully processed!"); }
From source file:edu.gslis.ts.DumpThriftData.java
public static void main(String[] args) { try {/*from w ww. j a va2 s . c o m*/ // Get the commandline options Options options = createOptions(); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); String in = cmd.getOptionValue("i"); String sentenceParser = cmd.getOptionValue("p"); String query = cmd.getOptionValue("q"); String externalCollection = cmd.getOptionValue("e"); // Get background statistics CollectionStats bgstats = new IndexBackedCollectionStats(); bgstats.setStatSource(externalCollection); // Set query GQuery gquery = new GQuery(); gquery.setText(query); gquery.setFeatureVector(new FeatureVector(query, null)); // Setup the filter DumpThriftData f = new DumpThriftData(); if (in != null) { File infile = new File(in); if (infile.isDirectory()) { for (File file : infile.listFiles()) { if (file.isDirectory()) { for (File filefile : file.listFiles()) { System.err.println(filefile.getAbsolutePath()); f.filter(filefile, sentenceParser, gquery, bgstats); } } else { System.err.println(file.getAbsolutePath()); f.filter(file, sentenceParser, gquery, bgstats); } } } else System.err.println(infile.getAbsolutePath()); f.filter(infile, sentenceParser, gquery, bgstats); } } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.cuhk.hccl.IDConverter.java
public static void main(String[] args) { if (args.length < 2) { printUsage();//from w ww .jav a 2 s. co m } try { File inFile = new File(args[0]); File outFile = new File(args[1]); if (inFile.isDirectory()) { System.out.println("ID Converting begins..."); FileUtils.forceMkdir(outFile); for (File file : inFile.listFiles()) { if (!file.isHidden()) processFile(file, new File(outFile.getAbsolutePath() + "/" + FilenameUtils.removeExtension(file.getName()) + "-long.txt")); } } else if (inFile.isFile()) { System.out.println("ID Converting begins..."); processFile(inFile, outFile); } else { printUsage(); } System.out.println("ID Converting finished."); } catch (IOException e) { e.printStackTrace(); } }