/** * Returns the canonical path to this file. * If the file is a URL, then the canonical path is equivalent to the * absolute file ({@link #getAbsoluteFile()}). Otherwise, this method * will delegate to {@link java.io.File#getCanonicalFile()}. * * @return see above * @throws IOException if the canonical path cannot be constructed * @see java.io.File#getCanonicalFile() */ public Location getCanonicalFile() throws IOException { return isURL ? getAbsoluteFile() : new Location(file.getCanonicalFile()); }
private static String findCaseInsensitive(Location name) throws IOException { // The file we're looking for doesn't exist, so look for it in the // same directory in a case-insensitive manner. Note that this will // throw an exception if multiple copies are found. return cache.lookup(name.getAbsoluteFile()).getAbsolutePath(); }
/** * Return a list of absolute files in this directory. Hidden files will * be included in the list. * If this is not a directory, return null. */ public Location[] listFiles() { String[] s = list(); if (s == null) return null; Location[] f = new Location[s.length]; for (int i=0; i<f.length; i++) { f[i] = new Location(getAbsolutePath(), s[i]); f[i] = f[i].getAbsoluteFile(); } return f; }
/** * Works like {@link #findSeriesPatterns(String, String, String[])}, * but dir and nameList are inferred from the given file's absolute * path. * * @param base The file basename to use as a template for the match. * @return an array containing all identified patterns. */ public static String[] findSeriesPatterns(String base) { Location file = new Location(base).getAbsoluteFile(); Location parent = file.getParentFile(); String[] list = parent.list(true); if (list == null) { list = new String[0]; } return findSeriesPatterns(base, parent.getAbsolutePath(), list); }
/** Finds the first file with one of the given suffixes. */ private Location find(final String[] suffix) { final Location file = new Location(currentId).getAbsoluteFile(); final Location parent = file.getParentFile(); final String[] listing = parent.list(); for (final String name : listing) { if (checkSuffix(name, suffix)) { return new Location(parent, name); } } return null; }
/** * Works like {@link #findSeriesPatterns(String, String, String[])}, * but dir and nameList are inferred from the given file's absolute * path. * * @param base The file basename to use as a template for the match. * @return an array containing all identified patterns. */ public static String[] findSeriesPatterns(String base) { Location file = new Location(base).getAbsoluteFile(); Location parent = file.getParentFile(); String[] list = parent.list(true); if (list == null) { list = new String[0]; } return findSeriesPatterns(base, parent.getAbsolutePath(), list); }
/** * Return a list of files in this directory, or null if this file is * not a directory. * * @return a list of absolute files in this directory. Hidden files will * be included in the list. If this is not a directory, return null. * @see #list() */ public Location[] listFiles() { String[] s = list(); if (s == null) return null; Location[] f = new Location[s.length]; for (int i=0; i<f.length; i++) { f[i] = new Location(getAbsolutePath(), s[i]); f[i] = f[i].getAbsoluteFile(); } return f; }
/** Finds the first file with one of the given suffixes. */ private Location find(final String[] suffix) { final Location file = new Location(currentId).getAbsoluteFile(); final Location parent = file.getParentFile(); final String[] listing = parent.list(); for (final String name : listing) { if (checkSuffix(name, suffix)) { return new Location(parent, name); } } return null; }
public Location getCanonicalFile() throws IOException { return isURL ? getAbsoluteFile() : new Location(file.getCanonicalFile()); }
private static String findCaseInsensitive(Location name) throws IOException { // The file we're looking for doesn't exist, so look for it in the // same directory in a case-insensitive manner. Note that this will // throw an exception if multiple copies are found. return cache.lookup(name.getAbsoluteFile()).getAbsolutePath(); }
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; }
private String[][] getTiffs() { final List<List<String>> files = new ArrayList<List<String>>(); Pattern p = Pattern.compile(".* - n\\d\\d\\d\\d\\d\\d\\.tif"); int nextWell = 0; for (String filename : rootList) { Location file = new Location(filename).getAbsoluteFile(); if (file.getName().startsWith("Well ") && file.isDirectory()) { String[] list = wellList.get(nextWell++); final List<String> tiffList = new ArrayList<String>(); for (String tiff : list) { if (p.matcher(tiff).matches()) { tiffList.add(new Location(file, tiff).getAbsolutePath()); } } files.add(tiffList); } } String[][] tiffFiles = new String[files.size()][]; for (int i=0; i<tiffFiles.length; i++) { tiffFiles[i] = files.get(i).toArray(new String[0]); } return tiffFiles; }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { Location file = new Location(id).getAbsoluteFile(); String name = file.getName(); if (name.equals(XML_FILE) || name.equals(EXPERIMENT_FILE) || name.equals(ACQUISITION_FILE)) { return true; } Location parent = file.getParentFile(); if (parent != null) { parent = parent.getParentFile(); } return new Location(parent, XML_FILE).exists(); }
@Override public boolean isThisType(String name, boolean open) { Location file = new Location(name).getAbsoluteFile(); return file.getName().equals("fid") || file.getName().equals("acqp"); }
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; }
private String[][] getTiffs() { final List<List<String>> files = new ArrayList<List<String>>(); Pattern p = Pattern.compile(".* - n\\d\\d\\d\\d\\d\\d\\.tif"); int nextWell = 0; for (String filename : rootList) { Location file = new Location(filename).getAbsoluteFile(); if (file.getName().startsWith("Well ") && file.isDirectory()) { String[] list = wellList.get(nextWell++); final List<String> tiffList = new ArrayList<String>(); for (String tiff : list) { if (p.matcher(tiff).matches()) { tiffList.add(new Location(file, tiff).getAbsolutePath()); } } files.add(tiffList); } } String[][] tiffFiles = new String[files.size()][]; for (int i=0; i<tiffFiles.length; i++) { tiffFiles[i] = files.get(i).toArray(new String[0]); } return tiffFiles; }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { Location file = new Location(id).getAbsoluteFile(); String name = file.getName(); if (name.equals(XML_FILE) || name.equals(EXPERIMENT_FILE) || name.equals(ACQUISITION_FILE)) { return true; } Location parent = file.getParentFile(); if (parent != null) { parent = parent.getParentFile(); } return new Location(parent, XML_FILE).exists(); }
@Override public boolean isThisType(String name, boolean open) { Location file = new Location(name).getAbsoluteFile(); return file.getName().equals("fid") || file.getName().equals("acqp"); }
private String locateExperimentFile(String id) throws FormatException, IOException { if (!checkSuffix(id, "exp")) { Location parent = new Location(id).getAbsoluteFile().getParentFile(); if (checkSuffix(id, "tif")) parent = parent.getParentFile(); Location expFile = new Location(parent, EXPERIMENT_FILE); if (expFile.exists()) { return expFile.getAbsolutePath(); } throw new FormatException("Could not find " + EXPERIMENT_FILE + " in " + parent.getAbsolutePath()); } return id; }
@Override public boolean isThisType(String name, boolean open) { if (checkSuffix(name, "rec") && open) { String base = new Location(name).getAbsoluteFile().getAbsolutePath(); base = base.substring(0, base.lastIndexOf(".")); String id = base + ".pcoraw"; return new Location(id).exists(); } if (checkSuffix(name, "pcoraw") && open) { return reader.isThisType(name, open); } return super.isThisType(name, open); }