@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 String[] getSeriesUsedFiles(boolean noPixels) { FormatTools.assertId(currentId, true, 1); String dir = pixelsFiles.get(getSeries()); Location realDir = new Location(dir).getParentFile(); realDir = realDir.getParentFile(); realDir = realDir.getParentFile(); dir = realDir.getAbsolutePath(); ArrayList<String> files = new ArrayList<String>(); files.add(new Location(getCurrentFile()).getAbsolutePath()); for (String f : allFiles) { if (f.startsWith(dir) && (!f.endsWith("2dseq") || !noPixels)) { if (!files.contains(f)) { files.add(f); } } } return files.toArray(new String[files.size()]); }
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; }
/** * Look up a filename in the cache. * @param name the name to look up (case insensitive). * @return the filename on disc (case sensitive). * @throws IOException */ public Location lookup(Location name) throws IOException { Location parent = name.getParentFile(); if (parent != null) { HashMap<String, String> s = fill(parent); if (s != null) { String realname = name.getName(); String lower = realname.toLowerCase(); String f = s.get(lower); if (f != null) { return new Location(parent, f); } } } return name; } }
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 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 String[] getSeriesUsedFiles(boolean noPixels) { FormatTools.assertId(currentId, true, 1); String dir = pixelsFiles.get(getSeries()); Location realDir = new Location(dir).getParentFile(); realDir = realDir.getParentFile(); realDir = realDir.getParentFile(); dir = realDir.getAbsolutePath(); ArrayList<String> files = new ArrayList<String>(); files.add(new Location(getCurrentFile()).getAbsolutePath()); for (String f : allFiles) { if (f.startsWith(dir) && (!f.endsWith("2dseq") || !noPixels)) { if (!files.contains(f)) { files.add(f); } } } return files.toArray(new String[files.size()]); }
/** * Look up a filename in the cache. * @param name the name to look up (case insensitive). * @return the filename on disc (case sensitive). * @throws IOException */ public Location lookup(Location name) throws IOException { Location parent = name.getParentFile(); if (parent != null) { HashMap<String, String> s = fill(parent); if (s != null) { String realname = name.getName(); String lower = realname.toLowerCase(); String f = s.get(lower); if (f != null) { return new Location(parent, f); } } } return name; } }
/** * 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); }
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; }
/** * Translate a file path from the XML file to an actual path on disk. * The path stored in the XML file may not have the same case as the path on * disk (typically all lower case on disk and possibly mixed case in XML). * If a matching file cannot be found, then the path from the XML file is returned. * * Uses {@link #directoryCache} so that any given directory is only listed once * per initialization, not once per lookup. */ private String lookup(String src) { Location f = new Location(src); String parent = f.getParent(); String name = f.getName(); String[] list = directoryCache.get(parent); if (list == null) { list = f.getParentFile().list(); Arrays.sort(list); directoryCache.put(parent, list); } for (String s : list) { if (s.equalsIgnoreCase(name)) { return new Location(f.getParentFile(), s).getAbsolutePath(); } } return src; }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { if (checkSuffix(id, "xml")) return false; Location file = new Location(id); String[] list = file.getParentFile().list(); for (String f : list) { if (checkSuffix(f, "xml") && DataTools.samePrefix(file.getName(), f)) { return false; } } return true; }
/** * 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; }
/** * Translate a file path from the XML file to an actual path on disk. * The path stored in the XML file may not have the same case as the path on * disk (typically all lower case on disk and possibly mixed case in XML). * If a matching file cannot be found, then the path from the XML file is returned. * * Uses {@link #directoryCache} so that any given directory is only listed once * per initialization, not once per lookup. */ private String lookup(String src) { Location f = new Location(src); String parent = f.getParent(); String name = f.getName(); String[] list = directoryCache.get(parent); if (list == null) { list = f.getParentFile().list(); Arrays.sort(list); directoryCache.put(parent, list); } for (String s : list) { if (s.equalsIgnoreCase(name)) { return new Location(f.getParentFile(), s).getAbsolutePath(); } } return src; }
@Override public boolean isSingleFile(String id) throws FormatException, IOException { if (checkSuffix(id, "xml")) return false; Location file = new Location(id); String[] list = file.getParentFile().list(); for (String f : list) { if (checkSuffix(f, "xml") && DataTools.samePrefix(file.getName(), f)) { return false; } } return true; }
/** * 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()); } } } }
/** 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; }
/** * 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()); } } } }
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; }