/** * Same as wrapArchive(AbstractFile) but using the given extension rather than the file's extension. */ public static AbstractFile wrapArchive(AbstractFile file, String extension) throws IOException { String filename = "tmp" + extension; ArchiveFormatProvider provider = getArchiveFormatProvider(filename); return provider != null ? provider.getFile(file) : file; }
/** * Returns the first <code>ArchiveFormatProvider</code> that matches the specified filename, <code>null</code> * if there is none. Note that if a filename matches the {@link java.io.FilenameFilter} of several registered * providers, the first provider matching the filename will be returned. * * @param filename an archive filename that potentially matches one of the registered <code>ArchiveFormatProvider</code> * @return the first <code>ArchiveFormatProvider</code> that matches the specified filename, <code>null</code> if there is none */ public static ArchiveFormatProvider getArchiveFormatProvider(String filename) { if(filename == null) return null; for (ArchiveFormatProvider provider : archiveFormatProviders) { if (provider.getFilenameFilter().accept(filename)) return provider; } return null; }
/** * Tests if the given file's extension matches that of one of the registered archive formats. * If it does, a corresponding {@link AbstractArchiveFile} instance is created on top of the provided file * and returned. If it doesn't, the provided <code>AbstractFile</code> instance is simply returned. * <p> * Note that return {@link AbstractArchiveFile} instances may not actually be archives according to * {@link AbstractFile#isArchive()}. An {@link AbstractArchiveFile} instance that is not currently an archive * (either non-existent or a directory) will behave as a regular (non-archive) file. This allows file instances to * go from being an archive to not being an archive (and vice-versa), without having to re-resolve the file. * </p> */ public static AbstractFile wrapArchive(AbstractFile file) throws IOException { String filename = file.getName(); // Looks for an archive FilenameFilter that matches the given filename. // Comparing the filename against each and every archive extension has a cost, so we only perform the test if // the filename contains a dot '.' character, since most of the time this method is called with a filename that // doesn't match any of the filters. if (filename.indexOf('.')!=-1) { ArchiveFormatProvider provider = getArchiveFormatProvider(filename); if (provider != null) { return provider.getFile(file); } } return file; }