// Use the ToolProvider interface for accessing the jar tool privatestaticfinal ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
.orElseThrow(() -> new RuntimeException("jar tool not found")
);
// Create JAR file with a STORED(non-compressed) entry
Files.writeString(Path.of(storedFileName), "foobar");
JAR_TOOL.run(System.out, System.err, "cM0vf", jarFileName, storedFileName);
// Replace the STORED entry using the default(DEFLATED) compression // method. try (FileSystem fs = FileSystems.newFileSystem(zipFile)) {
Files.writeString(fs.getPath(storedFileName), replacedValue);
}
Entry e1 = Entry.of(storedFileName, ZipEntry.DEFLATED, replacedValue);
verify(zipFile, e1);
}
/** *Verifythatthegivenpathisazipfilescontainingexactlythe *givenentries.
*/ privatestaticvoid verify(Path zipfile, Entry... entries) throws IOException { // check entries with zip API try (ZipFile zf = new ZipFile(zipfile.toFile())) { // check entry count
assertTrue(zf.size() == entries.length);
// check compression method and content of each entry for (Entry e : entries) {
ZipEntry ze = zf.getEntry(e.name);
assertTrue(ze != null);
assertTrue(ze.getMethod() == e.method); try (InputStream in = zf.getInputStream(ze)) { byte[] bytes = in.readAllBytes();
assertTrue(Arrays.equals(bytes, e.bytes));
}
}
}
// check entries with FileSystem API try (FileSystem fs = FileSystems.newFileSystem(zipfile)) { // check entry count
Path top = fs.getPath("/"); long count = Files.find(top, Integer.MAX_VALUE,
(path, attrs) -> attrs.isRegularFile()).count();
assertTrue(count == entries.length);
// check content of each entry for (Entry e : entries) {
Path file = fs.getPath(e.name); byte[] bytes = Files.readAllBytes(file);
assertTrue(Arrays.equals(bytes, e.bytes));
}
}
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.12Bemerkung:
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.