public Location getParentFile() { return new Location(getParent()); }
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; }
/** * Returns the abstract pathname of this abstract pathname's parent, or null * if this pathname does not name a parent directory. * * The parent of an abstract pathname consists of the pathname's prefix, if * any, and each name in the pathname's name sequence except for the last. * If the name sequence is empty then the pathname does not name a parent * directory. * * @return The abstract pathname of the parent directory named by this * abstract pathname, or null if this pathname does not name a parent * @see java.io.File#getParentFile() */ public Location getParentFile() { String parent = this.getParent(); if (parent == null) return null; return new Location(parent); }
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; }
/** 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(); }
/** * 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; }
/** * 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()); }
private void buildTIFFList(int posIndex) throws FormatException { Position p = positions.get(posIndex); CoreMetadata ms = core.get(posIndex); String parent = new Location(p.metadataFile).getParent();
/** * 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()); }
private void buildTIFFList(int posIndex) throws FormatException { Position p = positions.get(posIndex); CoreMetadata ms = core.get(posIndex); String parent = new Location(p.metadataFile).getParent();
/** 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( final String name, final boolean open ) { /* * We want to be pointed to any file in the directory that contains * 'MeasurementResult.xml'. */ final String localName = new Location( name ).getName(); if ( localName.equals( "MeasurementResult.xml" ) ) { return true; } final Location parent = new Location( name ).getAbsoluteFile().getParentFile(); Location xml = new Location( parent, "MeasurementResult.xml" ); if (!xml.exists() && parent != null) { if (parent.getParent() == null) { return false; } xml = new Location(parent.getParentFile(), "MeasurementResult.xml"); if (!xml.exists()) { return false; } } return super.isThisType( name, open ); }
@Test(groups = {"config-xml"}) public void writeXML() { setupReader(); if (!initFile(false)) return; String file = reader.getCurrentFile(); LOGGER.info("Generating XML: {}", file); try { Location l = new Location(file); File f = new File(l.getParent(), l.getName() + ".ome.xml"); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), Constants.ENCODING); MetadataStore store = reader.getMetadataStore(); MetadataRetrieve retrieve = omexmlService.asRetrieve(store); String xml = omexmlService.getOMEXML(retrieve); writer.write(xml); writer.close(); reader.close(); } catch (Throwable t) { LOGGER.info("", t); assert false; } }
@Override public boolean isThisType( final String name, final boolean open ) { /* * We want to be pointed to any file in the directory that contains * 'MeasurementResult.xml'. */ final String localName = new Location( name ).getName(); if ( localName.equals( "MeasurementResult.xml" ) ) { return true; } final Location parent = new Location( name ).getAbsoluteFile().getParentFile(); Location xml = new Location( parent, "MeasurementResult.xml" ); if (!xml.exists() && parent != null) { if (parent.getParent() == null) { return false; } xml = new Location(parent.getParentFile(), "MeasurementResult.xml"); if (!xml.exists()) { return false; } } return super.isThisType( name, open ); }
@Test(groups = {"config"}) public void writeConfigFile() throws IOException { setupReader(); if (!initFile(false)) return; String file = reader.getCurrentFile(); try { String parent = new Location(file).getParent(); String configDir = configTree.getConfigDirectory(); String rootDir = configTree.getRootDirectory(); if (configDir != null) { parent = parent.replaceAll(rootDir, configDir); File parentDir = new File(parent); if (!parentDir.exists()) { parentDir.mkdirs(); } } File f = new File(parent, ".bioformats"); LOGGER.info("Generating configuration: {}", f); Configuration newConfig = new Configuration(reader, f.getAbsolutePath()); newConfig.saveToFile(); } catch (Throwable t) { LOGGER.info("", t); assert false; } finally { reader.close(); } }
private FileInfo createFileInfo() { final FileInfo fi = new FileInfo(); // populate common FileInfo fields String idDir = process.getIdLocation() == null ? null : process.getIdLocation().getParent(); if (idDir != null && !idDir.endsWith(File.separator)) { idDir += File.separator; } fi.fileName = process.getIdName(); fi.directory = idDir; // dump OME-XML to ImageJ's description field, if available fi.description = process.getOMEXML(); return fi; }
private FileInfo createFileInfo() { final FileInfo fi = new FileInfo(); // populate common FileInfo fields String idDir = process.getIdLocation() == null ? null : process.getIdLocation().getParent(); if (idDir != null && !idDir.endsWith(File.separator)) { idDir += File.separator; } fi.fileName = process.getIdName(); fi.directory = idDir; // dump OME-XML to ImageJ's description field, if available fi.description = process.getOMEXML(); return fi; }
@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 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(); }