/** * Returns true if this pathname exists and represents a regular file. * * @see java.io.File#exists() */ public boolean isFile() { LOGGER.trace("isFile()"); return isURL ? (!isDirectory() && exists()) : file.isFile(); }
/** * Returns whether or not this file is a regular file (i.e. not a directory). * * @return true if this pathname exists and represents a regular file. * @see java.io.File#exists() */ public boolean isFile() { LOGGER.trace("isFile()"); return isURL ? (!isDirectory() && exists()) : file.isFile(); }
/** * If the underlying location is a URL, this method will return true if * the URL exists. * Otherwise, it will return true iff the file exists and is readable. * * @return see above * @see java.io.File#canRead() */ public boolean canRead() { LOGGER.trace("canRead()"); // Note: isFile calls exist return isURL ? (isDirectory() || isFile()) : file.canRead(); }
/** * If the underlying location is a URL, this method will return true if * the URL exists. * Otherwise, it will return true iff the file exists and is readable. * * @see java.io.File#canRead() */ public boolean canRead() { LOGGER.trace("canRead()"); return isURL ? (isDirectory() || isFile() || exists()) : file.canRead(); }
private String[] getAllFiles(String dir) { ArrayList<String> files = new ArrayList<String>(); Location root = new Location(dir); String[] children = root.list(); for (String child : children) { Location file = new Location(root, child); if (file.isDirectory()) { String[] grandchildren = getAllFiles(file.getAbsolutePath()); for (String g : grandchildren) { files.add(g); } } else { files.add(file.getAbsolutePath()); } } return files.toArray(new String[files.size()]); }
private String[] getAllFiles(String dir) { ArrayList<String> files = new ArrayList<String>(); Location root = new Location(dir); String[] children = root.list(); for (String child : children) { Location file = new Location(root, child); if (file.isDirectory()) { String[] grandchildren = getAllFiles(file.getAbsolutePath()); for (String g : grandchildren) { files.add(g); } } else { files.add(file.getAbsolutePath()); } } return files.toArray(new String[files.size()]); }
@Override public boolean isThisType(String name, boolean open) { Location location = new Location(name); String id = location.getAbsolutePath(); boolean dirCheck = location.isDirectory(); if (dirCheck) return false; if (name.endsWith(EXPERIMENT_FILE)) return true; if (!open) return false; try { id = locateExperimentFile(id); } catch (FormatException f) { return false; } catch (IOException f) { return false; } catch (NullPointerException e) { return false; } if (id.endsWith(EXPERIMENT_FILE)) { return true; } return super.isThisType(name, open); }
@Override public String[] getSeriesUsedFiles(boolean noPixels) { FormatTools.assertId(currentId, true, 1); final List<String> files = new ArrayList<String>(); files.addAll(used); if (getSeries() < xmlFiles.length) { Location xmlFile = new Location(xmlFiles[getSeries()]); if (xmlFile.exists() && !xmlFile.isDirectory()) { files.add(xmlFiles[getSeries()]); } } if (!noPixels && getSeries() < tiffFiles.length && new Location(tiffFiles[getSeries()]).exists()) { files.add(tiffFiles[getSeries()]); } return files.toArray(new String[files.size()]); }
@Override public String[] getSeriesUsedFiles(boolean noPixels) { FormatTools.assertId(currentId, true, 1); final List<String> files = new ArrayList<String>(); files.addAll(used); if (getSeries() < xmlFiles.length) { Location xmlFile = new Location(xmlFiles[getSeries()]); if (xmlFile.exists() && !xmlFile.isDirectory()) { files.add(xmlFiles[getSeries()]); } } if (!noPixels && getSeries() < tiffFiles.length && new Location(tiffFiles[getSeries()]).exists()) { files.add(tiffFiles[getSeries()]); } return files.toArray(new String[files.size()]); }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { if (new Location(id).isDirectory() && checkSuffix(id, "fake")) { fakeSeries.clear(); return listFakeSeries(id).size() <= 1; } if (checkSuffix(id, "fake" + ".ini")) { return ! new Location(id).exists(); } return ! new Location(id + ".ini").exists(); }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { if (new Location(id).isDirectory() && checkSuffix(id, "fake")) { fakeSeries.clear(); return listFakeSeries(id).size() <= 1; } if (checkSuffix(id, "fake" + ".ini")) { return ! new Location(id).exists(); } return ! new Location(id + ".ini").exists(); }
private String getMDBFile(String id) throws FormatException, IOException { Location parentFile = new Location(id).getAbsoluteFile().getParentFile(); String[] fileList = parentFile.list(); for (int i=0; i<fileList.length; i++) { if (fileList[i].startsWith(".")) continue; if (checkSuffix(fileList[i], MDB_SUFFIX)) { Location file = new Location(parentFile, fileList[i]).getAbsoluteFile(); if (file.isDirectory()) continue; // make sure that the .mdb references this .lsm String[] lsms = parseMDB(file.getAbsolutePath()); if (lsms == null) return null; for (String lsm : lsms) { if (id.endsWith(lsm) || lsm.endsWith(id)) { return file.getAbsolutePath(); } } } } return null; }
/** * Recursively add all of the files in the given directory to the * used file list. */ private void addDirectory(String path, int series) { Location dir = new Location(path); String[] files = dir.list(); if (files == null) return; for (String f : files) { Location file = new Location(path, f); if (file.isDirectory()) { addDirectory(file.getAbsolutePath(), series); } else if (checkSuffix(f, "scn")) { metadataFiles[series].add(file.getAbsolutePath()); } } }
/** * Recursively add all of the files in the given directory to the * used file list. */ private void addDirectory(String path, int series) { Location dir = new Location(path); String[] files = dir.list(); if (files == null) return; for (String f : files) { Location file = new Location(path, f); if (file.isDirectory()) { addDirectory(file.getAbsolutePath(), series); } else if (checkSuffix(f, "scn")) { metadataFiles[series].add(file.getAbsolutePath()); } } }
public static void parseConfigFiles(String dir, ConfigurationTree config) { Location root = new Location(dir); String[] files = root.list(); for (String file : files) { Location check = new Location(root, file); if (check.isDirectory()) { parseConfigFiles(check.getAbsolutePath(), config); } else if (isConfigFile(check, "")) { try { config.parseConfigFile(check.getAbsolutePath()); } catch (IOException e) { LOGGER.warn("Failed to parse config {}", check, e); } } } }
@Override public boolean isThisType(String name, boolean open) { if (checkSuffix(name, FV1000_SUFFIXES)) return true; if (!open) return false; // not allowed to touch the file system try { Location oif = new Location(findOIFFile(name)); return oif.exists() && !oif.isDirectory() && checkSuffix(oif.getAbsolutePath(), "oif") && !checkSuffix(name, "bmp"); } catch (IndexOutOfBoundsException e) { } catch (NullPointerException e) { } catch (FormatException e) { } return false; }
@Override public boolean isThisType(String name, boolean open) { if (checkSuffix(name, FV1000_SUFFIXES)) return true; if (!open) return false; // not allowed to touch the file system try { Location oif = new Location(findOIFFile(name)); return oif.exists() && !oif.isDirectory() && checkSuffix(oif.getAbsolutePath(), "oif") && !checkSuffix(name, "bmp"); } catch (IndexOutOfBoundsException e) { } catch (NullPointerException e) { } catch (FormatException e) { } return false; }
/** * DICOM datasets produced by: * http://www.ct-imaging.de/index.php/en/ct-systeme-e/mikro-ct-e.html * contain a bunch of extra metadata and log files. * * We do not parse these extra files, but do locate and attach them to the * DICOM file(s). */ private void attachCompanionFiles() throws IOException { Location parent = new Location(currentId).getAbsoluteFile().getParentFile(); Location grandparent = parent.getParentFile(); if (new Location(grandparent, parent.getName() + ".mif").exists()) { String[] list = grandparent.list(true); for (String f : list) { Location file = new Location(grandparent, f); if (!file.isDirectory()) { companionFiles.add(file.getAbsolutePath()); } } } }
/** * DICOM datasets produced by: * http://www.ct-imaging.de/index.php/en/ct-systeme-e/mikro-ct-e.html * contain a bunch of extra metadata and log files. * * We do not parse these extra files, but do locate and attach them to the * DICOM file(s). */ private void attachCompanionFiles() throws IOException { Location parent = new Location(currentId).getAbsoluteFile().getParentFile(); Location grandparent = parent.getParentFile(); if (new Location(grandparent, parent.getName() + ".mif").exists()) { String[] list = grandparent.list(true); for (String f : list) { Location file = new Location(grandparent, f); if (!file.isDirectory()) { companionFiles.add(file.getAbsolutePath()); } } } }
/** Recursively set delete-on-exit for a directory tree. */ private void deleteTemporaryDirectoryOnExit(Location directoryRoot) { directoryRoot.deleteOnExit(); Location[] children = directoryRoot.listFiles(); if (children != null) { for (Location child : children) { if (child.isDirectory()) { deleteTemporaryDirectoryOnExit(child); } else { child.deleteOnExit(); } } } }