/** * 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; }
private static Location findXML(String name) { Location parent = new Location(name).getAbsoluteFile().getParentFile(); Location xml = new Location(parent, XML_FILE); if (xml.exists()) { return xml; } if (parent.getParent() != null) { xml = new Location(parent.getParentFile(), XML_FILE); if (xml.exists()) { return xml; } } 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()); } } }
@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 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; }
private void findLogFiles() { iniFile = null; Location loc = new Location(getCurrentFile() + ".ini"); if (loc.exists()) { iniFile = loc.getAbsolutePath(); } }
@Override protected void initFile(String id) throws FormatException, IOException { // read the pattern from the file // the file should just contain a single line with the relative or // absolute file pattern currentId = new Location(id).getAbsolutePath(); String pattern = DataTools.readFile(id).trim(); String dir = new Location(id).getAbsoluteFile().getParent(); if (new Location(pattern).getParent() == null) { pattern = dir + File.separator + pattern; } helper.setUsingPatternIds(true); helper.setCanChangePattern(false); helper.setId(pattern); core = helper.getCoreMetadataList(); }
@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); }
/** Add the given file to the used files list. */ private void addUsedFile(String workingDirPath, String file) { if (file == null) return; Location f = new Location(workingDirPath, file); if (!workingDirPath.equals("")) allFiles.add(f.getAbsolutePath()); else allFiles.add(file); }
@Override public boolean isThisType(String name, boolean open) { if (checkSuffix(name, "xys")) return true; // verify that there is an .xys file in the same directory if (name.indexOf(' ') == -1) return false; if (!open) return false; String prefix = name.substring(0, name.lastIndexOf(" ")); Location xys = new Location(prefix + " 1.xys"); return xys.exists(); }
/** Gets the absolute path to the filename of the given {@link PFile}. */ private String getPath(final PFile file) { final Location f = new Location(xmlFile.getParent(), file.getFilename()); return f.getAbsolutePath(); }
@Override public boolean isThisType(String name, boolean open) { Location file = new Location(name).getAbsoluteFile(); return file.getName().equals("fid") || file.getName().equals("acqp"); }
@Override protected void initFile(String id) throws FormatException, IOException { TIFFInfo info = evalFile(id); if (new Location(info.origname).getAbsoluteFile().exists()) { super.initFile(info.origname); } else { super.initFile(id); } this.tiffInfo = info; super.initFileMain(info.origname); }
/** * Identifies the group pattern from a given file within that group. * * @param file The {@link Location} to use as a template for the match. * @return the identified pattern. */ public static String findPattern(Location file) { return findPattern(file.getName(), file.getAbsoluteFile().getParent()); }
/** * 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 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(); }
/** * 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()); }
/** * 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(); }