@Test public void testForName() { assertEquals(Archive.TAR, Archive.forName("tar")); assertEquals(Archive.TARGZ, Archive.forName("tar.gz")); assertEquals(Archive.ZIP, Archive.forName("zip")); }
public static Archive forName(final String name) { if(StringUtils.isNotBlank(name)) { for(Archive archive : getKnownArchives()) { for(String extension : archive.getExtensions()) { if(name.toLowerCase(Locale.ROOT).endsWith(extension.toLowerCase(Locale.ROOT))) { return archive; } } } } log.fatal(String.format("Unknown archive %s", name)); return null; }
Archive { public static Archive forName(final String name) { if(StringUtils.isNotBlank(name)) { for(Archive archive : getKnownArchives()) { for(String extension : archive.getExtensions()) { if(name.toLowerCase(Locale.ROOT).endsWith(extension.toLowerCase(Locale.ROOT))) { return archive; } } } } log.fatal(String.format("Unknown archive %s", name)); return null; } }
Archive { public static Archive forName(final String name) { if(StringUtils.isNotBlank(name)) { for(Archive archive : getKnownArchives()) { for(String extension : archive.getExtensions()) { if(name.toLowerCase(Locale.ROOT).endsWith(extension.toLowerCase(Locale.ROOT))) { return archive; } } } } log.fatal(String.format("Unknown archive %s", name)); return null; } private  Archive(final String extension); }
Archive { public static Archive forName(final String name) { if(StringUtils.isNotBlank(name)) { for(Archive archive : getKnownArchives()) { for(String extension : archive.getExtensions()) { if(name.toLowerCase(Locale.ROOT).endsWith(extension.toLowerCase(Locale.ROOT))) { return archive; } } } } log.fatal(String.format("Unknown archive %s", name)); return null; } private  Archive(final String extension); static Archive getDefault(); static Archive[] getKnownArchives(); static Archive forName(final String name); String[] getExtensions(); String getIdentifier(); abstract String getDescription(); Path getArchive(final List<Path> files); List<Path> getExpanded(final List<Path> files); String getTitle(final List<Path> files); String getCompressCommand(final Path workdir, final List<Path> files); String getDecompressCommand(final Path path); static boolean isArchive(final String filename); }
Archive { public static Archive forName(final String name) { if(StringUtils.isNotBlank(name)) { for(Archive archive : getKnownArchives()) { for(String extension : archive.getExtensions()) { if(name.toLowerCase(Locale.ROOT).endsWith(extension.toLowerCase(Locale.ROOT))) { return archive; } } } } log.fatal(String.format("Unknown archive %s", name)); return null; } private  Archive(final String extension); static Archive getDefault(); static Archive[] getKnownArchives(); static Archive forName(final String name); String[] getExtensions(); String getIdentifier(); abstract String getDescription(); Path getArchive(final List<Path> files); List<Path> getExpanded(final List<Path> files); String getTitle(final List<Path> files); String getCompressCommand(final Path workdir, final List<Path> files); String getDecompressCommand(final Path path); static boolean isArchive(final String filename); static final Archive TAR; static final Archive TARGZ; static final Archive TARBZ2; static final Archive ZIP; static final Archive GZIP; static final Archive BZ2; }