JarUtil { public static long getResourceSize(Path file, String resource) throws IOException { checkNotNull(resource); checkNotNull(file); URL url = getResourceUrl(file, resource); if (url == null) throw new IOException(); return Resources.asByteSource(url).size(); } private  JarUtil(); static Optional<String> getManifestValue(Path file, String attribute); static Optional<String> getManifestValue(File file, String attribute); static Attributes getManifest(Path file); static Attributes getManifest(File file); static long getResourceSize(Path file, String resource); static long getResourceSize(File file, String resource); static URL getResourceUrl(Path file, String resource); static boolean resourceExists(Path file, String resource);  }
@Test @DisplayName("Get size of jar resources") void getResourceSize_1() throws IOException { assertEquals(88, getResourceSize(new File("src/test/resources/small_program.jar"), "/META-INF/MANIFEST.MF")); assertEquals(88, getResourceSize(new File("src/test/resources/small_program.jar"), "META-INF/MANIFEST.MF")); }
@Test @DisplayName("Try to get the size of nonexistent resources") void getResourceSize_2() { assertThrows(IOException.class, () -> getResourceSize(new File("src/test/resources/small_program.jar"), "META-INF/MANIFEST.MF2")); assertThrows(IOException.class, () -> getResourceSize(new File("src/test/resources/small_program.jar"), "")); }
@Test @DisplayName("Try to get the size of resources in a nonexistent file") void getResourceSize_3() { assertThrows(IOException.class, () -> getResourceSize(new File("src/test/resources/nonexist.jar"), "META-INF/MANIFEST.MF2")); }
@Test @DisplayName("Try to get the size of resources from an invalid file type") void getResourceSize_4() { assertThrows(IOException.class, () -> getResourceSize(new File("src/test/resources/small_file.txt"), "META-INF/MANIFEST.MF")); assertThrows(IOException.class, () -> getResourceSize(new File("src/test/resources"), "META-INF/MANIFEST.MF")); }