Search in sources :

Example 56 with ZipInputStream

use of java.util.zip.ZipInputStream in project bazel by bazelbuild.

the class ZipCombinerTest method testMergeStrategyWithSlowCopy.

@Test
public void testMergeStrategyWithSlowCopy() throws IOException {
    MockZipEntryFilter mockFilter = new MockZipEntryFilter();
    mockFilter.behavior.put("hello.txt", new SlowConcatenateStrategy());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipCombiner zipCombiner = new ZipCombiner(mockFilter, out)) {
        zipCombiner.addZip(sampleZip());
        zipCombiner.addZip(sampleZipWithTwoEntries());
    }
    assertEquals(Arrays.asList("hello.txt", "hello2.txt"), mockFilter.calls);
    ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
    assertEntry(zipInput, "hello2.txt", "Hello World 2!");
    assertEntry(zipInput, "hello.txt", "Hello World!Hello World!");
    assertNull(zipInput.getNextEntry());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 57 with ZipInputStream

use of java.util.zip.ZipInputStream 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 58 with ZipInputStream

use of java.util.zip.ZipInputStream 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 59 with ZipInputStream

use of java.util.zip.ZipInputStream 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 60 with ZipInputStream

use of java.util.zip.ZipInputStream in project jadx by skylot.

the class ClsSet method load.

public void load(File input) throws IOException, DecodeException {
    String name = input.getName();
    InputStream inputStream = new FileInputStream(input);
    try {
        if (name.endsWith(CLST_EXTENSION)) {
            load(inputStream);
        } else if (name.endsWith(".jar")) {
            ZipInputStream in = new ZipInputStream(inputStream);
            try {
                ZipEntry entry = in.getNextEntry();
                while (entry != null) {
                    if (entry.getName().endsWith(CLST_EXTENSION)) {
                        load(in);
                    }
                    entry = in.getNextEntry();
                }
            } finally {
                close(in);
            }
        } else {
            throw new JadxRuntimeException("Unknown file format: " + name);
        }
    } finally {
        close(inputStream);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) DataInputStream(java.io.DataInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) FileInputStream(java.io.FileInputStream)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)968 ZipEntry (java.util.zip.ZipEntry)762 IOException (java.io.IOException)355 File (java.io.File)319 FileInputStream (java.io.FileInputStream)316 InputStream (java.io.InputStream)203 FileOutputStream (java.io.FileOutputStream)198 ByteArrayInputStream (java.io.ByteArrayInputStream)190 ByteArrayOutputStream (java.io.ByteArrayOutputStream)138 BufferedInputStream (java.io.BufferedInputStream)127 ZipOutputStream (java.util.zip.ZipOutputStream)91 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)80 OutputStream (java.io.OutputStream)67 URL (java.net.URL)58 Path (java.nio.file.Path)58 FileNotFoundException (java.io.FileNotFoundException)56 HashMap (java.util.HashMap)56 BufferedOutputStream (java.io.BufferedOutputStream)54 ZipFile (java.util.zip.ZipFile)43