LegacyUtilities { public static String guessScheme(@Nullable String filename) { if (filename != null) { int start, end; start = end = filename.length(); while (start > 0) { char c = filename.charAt(--start); if (c == '/') { break; } else if (c == '.') { switch (Ascii.toLowerCase(filename.substring(start + 1, end))) { case "zip": case "bz": case "z": case "nupg": case "xpi": case "egg": case "jar": case "war": case "rar": case "apk": case "ear": case "car": case "nbm": return "zip"; case "rpm": return "rpm"; case "tar": case "tgz": case "txz": case "tbz": case "tbz2": return "tar"; case "a": case "ar": case "deb": case "lib": return "ar"; case "arj": return "arj"; case "7z": return "sevenZ"; default: end = start; } } } } return "unknown"; }  static ObjectMapper scanContainerObjectMapper(); static int averageEntryNodeCount(); static Stream<List<Map<String, Object>>> partitionNodes(BdioMetadata metadata, Stream<Map<String, Object>> nodes); static int estimateSize(@Nullable Object obj); static int estimateEntryOverhead(BdioMetadata metadata); static void mergeDependency(Multimap<String, Dependency> dependencies, Dependency dependency); static String guessScheme(@Nullable String filename); static String toFileUri(@Nullable String hostName, @Nullable String baseDir, @Nullable String fragment); static String toNameUri(String name);  }
@Test public void guessScheme() { String[][] data = new String[][] { { "Simple ZIP", "foobar.zip", "zip" }, { "Inner ZIP extension", "foobar.zip.foo", "zip" }, { "Case insensitive ZIP", "foobar.ZIP", "zip" }, { "Compressed TAR, separate extension", "foobar.tar.gz", "tar" }, { "Compressed TAR, combined extension", "foobar.tgz", "tar" }, { "Dot-dot", "foobar.zip..foo", "zip" }, { "Ignore file name", "zip.foo", "unknown" }, { "Ignore path", "foo.zip/bar.foo", "unknown" }, }; for (String[] testCase : data) { assertThat(LegacyUtilities.guessScheme(testCase[1])).named(testCase[0]).isEqualTo(testCase[2]); } }