/** * 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; }
/** * 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; }