/** *@test *@summaryVerifythattheoutputstreamcreatedforzipfileentries,throughtheZipFileSystem *worksfineforvaryingsizesofthezipfileentries *@bug819075380111468279536 *@runtestng/timeout=300ZipFSOutputStreamTest
*/ publicclass ZipFSOutputStreamTest { // List of files to be added to the ZIP file along with their sizes in bytes privatestaticfinal Map<String, Long> ZIP_ENTRIES = Map.of( "f1", Integer.MAX_VALUE + 1L, // a value which when cast to an integer, becomes a negative value "f2", 25L * 1024L * 1024L, // 25 MB "d1/f3", 1234L, "d1/d2/f4", 0L);
/** *Createazipfilesystemandwriteoutentriesofvaryingsizesusingtheoutputstreamreturned *bytheZipFileSystem.Thenverifythatthegeneratedzipfileentriesareasexpected, *bothinsizeandcontent
*/
@Test(dataProvider = "zipFSCreationEnv") publicvoid testOutputStream(final Map<String, ?> env) throws Exception { finalbyte[] chunk = newbyte[1024]; // fill it with some fixed content (the fixed content will later on help ease // the verification of the content written out)
Arrays.fill(chunk, (byte) 42); try (final FileSystem zipfs = FileSystems.newFileSystem(ZIP_FILE, env)) { // create the zip with varying sized entries for (final Map.Entry<String, Long> entry : ZIP_ENTRIES.entrySet()) { final Path entryPath = zipfs.getPath(entry.getKey()); if (entryPath.getParent() != null) {
Files.createDirectories(entryPath.getParent());
} long start = System.currentTimeMillis(); try (final OutputStream os = Files.newOutputStream(entryPath)) {
writeAsChunks(os, chunk, entry.getValue());
}
System.out.println("Wrote entry " + entryPath + " of bytes " + entry.getValue()
+ " in " + (System.currentTimeMillis() - start) + " milli seconds");
}
} // now verify the written content try (final FileSystem zipfs = FileSystems.newFileSystem(ZIP_FILE)) { for (final Map.Entry<String, Long> entry : ZIP_ENTRIES.entrySet()) { final Path entryPath = zipfs.getPath(entry.getKey()); try (final InputStream is = Files.newInputStream(entryPath)) { finalbyte[] buf = newbyte[chunk.length]; int numRead; long totalRead = 0; long start = System.currentTimeMillis(); while ((numRead = is.read(buf)) != -1) {
totalRead += numRead; // verify the content Assert.assertEquals(Arrays.mismatch(buf, 0, numRead, chunk, 0, numRead), -1, "Unexpected content in " + entryPath);
}
System.out.println("Read entry " + entryPath + " of bytes " + totalRead
+ " in " + (System.currentTimeMillis() - start) + " milli seconds"); Assert.assertEquals(totalRead, (long) entry.getValue(), "Unexpected number of bytes read from zip entry " + entryPath);
}
}
}
}
/** *Repeatedlywritesouttotheoutputstream,thechunkofdata,tillthenumberofbytes *writtentothestreamequalsthetotalSize
*/ privatestaticvoid writeAsChunks(final OutputStream os, finalbyte[] chunk, finallong totalSize) throws IOException { long remaining = totalSize; for (long l = 0; l < totalSize; l += chunk.length) { finalint numToWrite = (int) Math.min(remaining, chunk.length);
os.write(chunk, 0, numToWrite);
remaining -= numToWrite;
}
}
}
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.11Bemerkung:
(vorverarbeitet am 2026-10-12)
¤
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.