List of usage examples for java.io File list
public String[] list()
From source file:eu.scape_project.cdx_creator.CDXCreator.java
/** * Traverse the root directory recursively * * @param dir Root directory/* w w w . j a v a 2 s .c o m*/ * @throws FileNotFoundException * @throws IOException */ private void traverseDir(File dirStructItem) { if (dirStructItem.isDirectory()) { String[] children = dirStructItem.list(); for (String child : children) { traverseDir(new File(dirStructItem, child)); } } else if (!dirStructItem.isDirectory()) { String filePath = dirStructItem.getAbsolutePath(); if (RegexUtils.pathMatchesRegexFilter(filePath, config.getInputPathRegexFilter())) { CDXCreationTask cdxCreationTask = new CDXCreationTask(config, dirStructItem, dirStructItem.getName()); cdxCreationTask.createIndex(); } } }
From source file:dk.netarkivet.archive.webinterface.BatchGUI.java
/** * Creates the HTML code for describing the previous executions of a given batchjob. If any previous results are * found, then a table will be created. Each result (output and/or error file) will have an entry in the table. A * row containing the following: <br/> * - The start date (extractable from the result file name). <br/> * - The end date (last modified date for either result file). <br/> * - The size of the output file.<br/> * - The number of lines in the output file. <br/> * - A link to download the output file.<br/> * - The size of the error file.<br/> * - The number of lines in the error file. <br/> * - A link to download the error file.<br/> * * @param jobPath The name of the batch job. * @param locale The locale language package. * @return The HTML code for describing the previous executions of the batchjob. */// w ww . j a va 2 s . c om private static String getPreviousRuns(String jobPath, Locale locale) { // initialize the resulting string. StringBuilder res = new StringBuilder(); // extract the final name of the batch job (used for the files). String batchName = getJobName(jobPath); // extract the batch directory, where the old batchjobs files lies. File batchDir = getBatchDir(); // extract the files for the batchjob. String[] filenames = batchDir.list(); // use a hash-set to avoid counting both '.err' and '.out' files. Set<String> prefixes = new HashSet<String>(); for (String filename : filenames) { // match and put into set. if (filename.startsWith(batchName) && (filename.endsWith(Constants.ERROR_FILE_EXTENSION) || filename.endsWith(Constants.OUTPUT_FILE_EXTENSION))) { String prefix = filename.split("[.]")[0]; // the prefix is not added twice, since it is a hash-set. prefixes.add(prefix); } } // No files => No previous runs. if (prefixes.isEmpty()) { res.append(I18N.getString(locale, "batchpage;Batchjob.has.never.been.run", new Object[] {}) + "<br/><br/>\n"); return res.toString(); } // make header of output res.append(I18N.getString(locale, "batchpage;Number.of.runs.0", prefixes.size()) + "<br/>\n"); res.append("<table class=\"selection_table\" cols=\"3\">\n"); res.append(" <tr>\n"); res.append(" <th colspan=\"1\">" + I18N.getString(locale, "batchpage;Started.date", new Object[] {}) + "</th>\n"); res.append(" <th colspan=\"1\">" + I18N.getString(locale, "batchpage;Ended.date", new Object[] {}) + "</th>\n"); res.append(" <th colspan=\"3\">" + I18N.getString(locale, "batchpage;Output.file", new Object[] {}) + "</th>\n"); res.append(" <th colspan=\"3\">" + I18N.getString(locale, "batchpage;Error.file", new Object[] {}) + "</th>\n"); res.append(" </tr>\n"); int i = 0; for (String prefix : prefixes) { res.append(" <tr class=" + HTMLUtils.getRowClass(i++) + ">\n"); File outputFile = new File(batchDir, prefix + ".out"); File errorFile = new File(batchDir, prefix + ".err"); // Retrieve the timestamp from the file-name or "" if not found String timestamp = getTimestamp(prefix, locale); // insert start-time res.append(" <td>" + timestamp + "</td>\n"); // retrieve the last-modified date for the files Long lastModified = 0L; if (outputFile.exists() && outputFile.lastModified() > lastModified) { lastModified = outputFile.lastModified(); } if (errorFile.exists() && errorFile.lastModified() > lastModified) { lastModified = errorFile.lastModified(); } // insert ended-time res.append(" <td>" + new Date(lastModified).toString() + "</td>\n"); // insert information about the output file. if (!outputFile.exists()) { res.append(" <td>" + I18N.getString(locale, "batchpage;No.outputfile", new Object[] {}) + "</td>\n"); res.append(" <td>" + I18N.getString(locale, "batchpage;No.outputfile", new Object[] {}) + "</td>\n"); res.append(" <td>" + I18N.getString(locale, "batchpage;No.outputfile", new Object[] {}) + "</td>\n"); } else { res.append(" <td>" + outputFile.length() + " " + I18N.getString(locale, "batchpage;bytes", new Object[] {}) + "</td>\n"); res.append(" <td>" + FileUtils.countLines(outputFile) + " " + I18N.getString(locale, "batchpage;lines", new Object[] {}) + "</td>\n"); res.append(" <td><a href=" + Constants.URL_RETRIEVE_RESULT_FILES + "?filename=" + outputFile.getName() + ">" + I18N.getString(locale, "batchpage;Download.outputfile", new Object[] {}) + "</a></td>\n"); } // insert information about error file if (!errorFile.exists()) { res.append( " <td>" + I18N.getString(locale, "batchpage;No.errorfile", new Object[] {}) + "</td>\n"); res.append( " <td>" + I18N.getString(locale, "batchpage;No.errorfile", new Object[] {}) + "</td>\n"); res.append( " <td>" + I18N.getString(locale, "batchpage;No.errorfile", new Object[] {}) + "</td>\n"); } else { res.append(" <td>" + errorFile.length() + " " + I18N.getString(locale, "batchpage;bytes", new Object[] {}) + "</td>\n"); res.append(" <td>" + FileUtils.countLines(errorFile) + " " + I18N.getString(locale, "batchpage;lines", new Object[] {}) + "</td>\n"); res.append(" <td><a href=" + Constants.URL_RETRIEVE_RESULT_FILES + "?filename=" + errorFile.getName() + ">" + I18N.getString(locale, "batchpage;Download.errorfile", new Object[] {}) + "</a></td>\n"); } // end row res.append(" </tr>\n"); } res.append("</table>\n"); return res.toString(); }
From source file:at.ait.dme.magicktiler.MagickTilerCLI.java
private static void generateTiles(MagickTiler tiler, File input, File destination, String consoleOutScheme, String consoleOutFormat) { long startTime = System.currentTimeMillis(); System.out.println("Generating " + consoleOutScheme + " from file " + input.getAbsolutePath() + " " + consoleOutFormat);/*w ww. j av a2 s. c om*/ if (destination != null) { System.out.println("Destination: " + destination.getAbsolutePath()); } if (input.isFile()) { // Tile single file try { tiler.convert(input, destination); } catch (TilingException e) { System.out.println(e.getMessage()); } } else { // Tile folder full of files long ctrFiles = 0; long ctrTilesets = 0; tiler.setWorkingDirectory(input); String files[] = input.list(); logger.info(files.length + " files/subdirs in folder"); logger.info("--------------------------------------------------------------"); for (int i = 0; i < files.length; i++) { File child = new File(input, files[i]); try { if (child.isFile()) { long tileStartTime = System.currentTimeMillis(); ctrFiles++; tiler.convert(child, destination); ctrTilesets++; logger.info("[DONE] " + child.getName() + " (" + (System.currentTimeMillis() - tileStartTime) + " ms)"); } } catch (TilingException e) { logger.info("[SKIPPED] " + child.getName() + " - " + e.getMessage()); } } long duration = (System.currentTimeMillis() - startTime) / 60000; logger.info("--------------------------------------------------------------"); logger.info(ctrFiles + " files processed"); logger.info(ctrTilesets + " tilesets created (" + duration + " min)"); } }
From source file:com.haulmont.cuba.core.sys.javacl.SourceProvider.java
public List<String> getAllClassesFromPackage(@Nullable String packageName) { String path = packageName != null ? packageName.replace(".", "/") : null; File srcDir = path != null ? new File(rootDir, path) : new File(rootDir); String[] fileNames = srcDir.list(); List<String> classNames = new ArrayList<>(); if (fileNames != null) { for (String fileName : fileNames) { if (fileName.endsWith(JAVA_EXT)) { String className = fileName.replace(JAVA_EXT, ""); String fullClassName = packageName != null ? packageName + "." + className : className; classNames.add(fullClassName); }/* ww w . j ava 2 s . c o m*/ } } return classNames; }
From source file:com.vecna.taglib.processor.JspTagFileProcessor.java
/** * Scan a directory with tag files and add info about them to a taglib model * @param root webapp root directory// www. j ava 2 s.c o m * @param tagDir tag directory relative to the webapp root * @param taglib taglib model object */ public void addLocalMetadata(String root, String tagDir, JspTaglibModel taglib) { File dir = new File(root + File.separator + tagDir); if (dir.exists() && dir.isDirectory()) { String[] files = dir.list(); for (String file : files) { if (file.endsWith(".tag")) { JspTagFileModel tagFile = new JspTagFileModel(); tagFile.name = StringUtils.removeEnd(file, ".tag"); tagFile.path = tagDir + File.separator + file; taglib.tagFiles.add(tagFile); } } } }
From source file:FileTreeFrame.java
public int getChildCount(Object parent) { File file = (File) parent; if (file.isDirectory()) { String[] fileList = file.list(); if (fileList != null) return file.list().length; }/* w w w . j a v a 2 s . c o m*/ return 0; }
From source file:com.adito.util.Utils.java
public static boolean isWindows64JREAvailable() { try {//from w w w . j av a 2 s .co m String javaHome = new File(System.getProperty("java.home")).getCanonicalPath(); try { if (System.getProperty("os.name").startsWith("Windows")) { int dataModel = Integer.parseInt(System.getProperty("sun.arch.data.model")); if (dataModel != 64) { int idx = javaHome.indexOf(" (x86)"); if (idx > -1) { // Looks like we have a 32bit Java version installed on 64 bit Windows String programFiles = javaHome.substring(0, idx); File j = new File(programFiles, "Java"); if (j.exists()) { // We may have a 64 bit version of Java installed. String[] jres = j.list(); for (int i = 0; i < jres.length; i++) { File h = new File(j, jres[i]); File exe = new File(h, "bin\\java.exe"); if (exe.exists()) { // Found a 64bit version of java return true; } } } } } } } catch (NumberFormatException ex) { } return false; } catch (IOException ex) { return false; } }
From source file:gr.aueb.mipmapgui.controller.file.ActionInitialize.java
private void getSavedSchemata() { JSONArray schemaFileArr = new JSONArray(); File schemaDir = new File(Costanti.SERVER_MAIN_FOLDER + Costanti.SERVER_SCHEMATA_FOLDER); String[] schemaFiles = schemaDir.list(); for (String file : schemaFiles) { file = file.substring(0, file.lastIndexOf('.')); schemaFileArr.add(file);//from w ww . j ava 2 s . c o m } JSONObject.put("savedSchemata", schemaFileArr); }
From source file:SortTreeDemo.java
protected void fillModel(SortTreeModel model, DefaultMutableTreeNode current) { PrettyFile pf = (PrettyFile) current.getUserObject(); File f = pf.getFile(); if (f.isDirectory()) { String files[] = f.list(); // ignore "." files for (int i = 0; i < files.length; i++) { if (files[i].startsWith(".")) continue; PrettyFile tmp = new PrettyFile(pf, files[i]); DefaultMutableTreeNode node = new DefaultMutableTreeNode(tmp); model.insertNodeInto(node, current); if (tmp.getFile().isDirectory()) { fillModel(model, node);/*from w ww . jav a 2 s . c o m*/ } } } }
From source file:com.github.tteofili.p2h.DataSplitTest.java
@Ignore @Test/* w w w . j av a 2s . c o m*/ public void testDataSplit() throws Exception { String regex = "\\n\\d(\\.\\d)*\\.?\\u0020[\\w|\\-|\\|\\:]+(\\u0020[\\w|\\-|\\:|\\]+){0,10}\\n"; String prefix = "/path/to/h2v/"; Pattern pattern = Pattern.compile(regex); Path path = Paths.get(getClass().getResource("/papers/raw/").getFile()); File file = path.toFile(); if (file.exists() && file.list() != null) { for (File doc : file.listFiles()) { String s = IOUtils.toString(new FileInputStream(doc)); String docName = doc.getName(); File fileDir = new File(prefix + docName); assert fileDir.mkdir(); Matcher matcher = pattern.matcher(s); int start = 0; String sectionName = "abstract"; while (matcher.find(start)) { String string = matcher.group(0); if (isValid(string)) { String content; if (start == 0) { // abstract content = s.substring(0, matcher.start()); } else { content = s.substring(start, matcher.start()); } File f = new File(prefix + docName + "/" + docName + "_" + sectionName); assert f.createNewFile() : "could not create file" + f.getAbsolutePath(); FileOutputStream outputStream = new FileOutputStream(f); IOUtils.write(content, outputStream); start = matcher.end(); sectionName = string.replaceAll("\n", "").trim(); } else { start = matcher.end(); } } // remaining File f = new File(prefix + docName + "/" + docName + "_" + sectionName); assert f.createNewFile(); FileOutputStream outputStream = new FileOutputStream(f); IOUtils.write(s.substring(start), outputStream); } } }