Search in sources :

Example 51 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.

the class ZipCombinerTest method testCopyTwoUncompressedEntries.

@Test
public void testCopyTwoUncompressedEntries() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
        zipCombiner.addZip(sampleZipWithTwoUncompressedEntries());
    }
    ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
    assertEntry(zipInput, "hello.txt", "Hello World!");
    assertEntry(zipInput, "hello2.txt", "Hello World 2!");
    assertNull(zipInput.getNextEntry());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 52 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.

the class ZipCombinerTest method testCombine.

@Test
public void testCombine() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
        zipCombiner.addZip(sampleZip());
        zipCombiner.addZip(sampleZip2());
    }
    ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
    assertEntry(zipInput, "hello.txt", "Hello World!");
    assertEntry(zipInput, "hello2.txt", "Hello World 2!");
    assertNull(zipInput.getNextEntry());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 53 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.

the class ZipCombinerTest method testCopyDateHandling.

@Test
public void testCopyDateHandling() throws IOException {
    final Date date = new GregorianCalendar(2009, 8, 2, 0, 0, 0).getTime();
    ZipEntryFilter mockFilter = new ZipEntryFilter() {

        @Override
        public void accept(String filename, StrategyCallback callback) throws IOException {
            assertEquals("hello.txt", filename);
            callback.copy(date);
        }
    };
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
        zipCombiner.addZip(sampleZip());
    }
    ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
    assertEntry(zipInput, "hello.txt", date, "Hello World!");
    assertNull(zipInput.getNextEntry());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GregorianCalendar(java.util.GregorianCalendar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(java.util.Date) Test(org.junit.Test)

Example 54 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream 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)

Example 55 with ByteArrayOutputStream

use of java.io.ByteArrayOutputStream in project bazel by bazelbuild.

the class ZipCombinerTest method testCopyCallsFilter.

@Test
public void testCopyCallsFilter() throws IOException {
    MockZipEntryFilter mockFilter = new MockZipEntryFilter();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
        zipCombiner.addZip(sampleZip());
    }
    assertEquals(Arrays.asList("hello.txt"), mockFilter.calls);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)8438 Test (org.junit.Test)2232 ByteArrayInputStream (java.io.ByteArrayInputStream)2148 IOException (java.io.IOException)2037 PrintStream (java.io.PrintStream)800 InputStream (java.io.InputStream)765 ObjectOutputStream (java.io.ObjectOutputStream)759 DataOutputStream (java.io.DataOutputStream)705 ObjectInputStream (java.io.ObjectInputStream)361 File (java.io.File)331 OutputStream (java.io.OutputStream)318 HashMap (java.util.HashMap)279 ArrayList (java.util.ArrayList)264 FileInputStream (java.io.FileInputStream)211 OutputStreamWriter (java.io.OutputStreamWriter)207 DataInputStream (java.io.DataInputStream)198 Test (org.testng.annotations.Test)184 PrintWriter (java.io.PrintWriter)162 URL (java.net.URL)160 Map (java.util.Map)158