use of com.google.devtools.build.zip.ExtraData in project bazel by bazelbuild.
the class ZipCombinerTest method testZipCombinerAgainstJavaUtil.
@Test
public void testZipCombinerAgainstJavaUtil() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (JarOutputStream jarOut = new JarOutputStream(out)) {
ZipEntry entry;
entry = new ZipEntry("META-INF/");
entry.setTime(ZipCombiner.DOS_EPOCH.getTime());
entry.setMethod(JarOutputStream.STORED);
entry.setSize(0);
entry.setCompressedSize(0);
entry.setCrc(0);
jarOut.putNextEntry(entry);
entry = new ZipEntry("META-INF/MANIFEST.MF");
entry.setTime(ZipCombiner.DOS_EPOCH.getTime());
entry.setMethod(JarOutputStream.DEFLATED);
jarOut.putNextEntry(entry);
jarOut.write(new byte[] { 1, 2, 3, 4 });
}
File javaFile = writeInputStreamToFile(new ByteArrayInputStream(out.toByteArray()));
out.reset();
try (ZipCombiner zipcombiner = new ZipCombiner(out)) {
zipcombiner.addDirectory("META-INF/", ZipCombiner.DOS_EPOCH, new ExtraData[] { new ExtraData((short) 0xCAFE, new byte[0]) });
zipcombiner.addFile("META-INF/MANIFEST.MF", ZipCombiner.DOS_EPOCH, new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }));
}
File zipCombinerFile = writeInputStreamToFile(new ByteArrayInputStream(out.toByteArray()));
byte[] zipCombinerRaw = out.toByteArray();
new ZipTester(zipCombinerRaw).validate();
assertZipFilesEquivalent(new ZipReader(zipCombinerFile), new ZipReader(javaFile));
}
Aggregations