Search in sources :

Example 1 with ExtraData

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) ZipReader(com.google.devtools.build.zip.ZipReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExtraData(com.google.devtools.build.zip.ExtraData) File(java.io.File) Test(org.junit.Test)

Aggregations

ExtraData (com.google.devtools.build.zip.ExtraData)1 ZipReader (com.google.devtools.build.zip.ZipReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 JarOutputStream (java.util.jar.JarOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 Test (org.junit.Test)1