Search in sources :

Example 41 with ZipInputStream

use of java.util.zip.ZipInputStream in project robovm by robovm.

the class ZipInputStreamTest method unzip.

public static byte[] unzip(String name, byte[] bytes) throws IOException {
    ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(bytes));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ZipEntry entry = in.getNextEntry();
    assertEquals(name, entry.getName());
    byte[] buffer = new byte[1024];
    int count;
    while ((count = in.read(buffer)) != -1) {
        out.write(buffer, 0, count);
    }
    // There's only one entry in the Zip files we create.
    assertNull(in.getNextEntry());
    in.close();
    return out.toByteArray();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 42 with ZipInputStream

use of java.util.zip.ZipInputStream in project robovm by robovm.

the class ZipFileTest method testInflatingStreamsRequiringZipRefill.

public void testInflatingStreamsRequiringZipRefill() throws IOException {
    int originalSize = 1024 * 1024;
    byte[] readBuffer = new byte[8192];
    ZipInputStream in = new ZipInputStream(new FileInputStream(createZipFile(1, originalSize)));
    while (in.getNextEntry() != null) {
        while (in.read(readBuffer, 0, readBuffer.length) != -1) {
        }
    }
    in.close();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream)

Example 43 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)

Example 44 with ZipInputStream

use of java.util.zip.ZipInputStream in project platform_frameworks_base by android.

the class BugreportReceiverTest method assertZipContent.

private void assertZipContent(Uri uri, String entryName, String expectedContent) throws IOException, IOException {
    Log.v(TAG, "assertZipEntry(uri=" + uri + ", entryName=" + entryName);
    try (ZipInputStream zis = new ZipInputStream(mContext.getContentResolver().openInputStream(uri))) {
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            Log.v(TAG, "Zip entry: " + entry.getName());
            if (entry.getName().equals(entryName)) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                Streams.copy(zis, bos);
                String actualContent = new String(bos.toByteArray(), "UTF-8");
                bos.close();
                assertEquals("wrong content for zip entry'" + entryName + "' on '" + uri + "'", expectedContent, actualContent);
                return;
            }
        }
    }
    fail("Did not find entry '" + entryName + "' on file '" + uri + "'");
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 45 with ZipInputStream

use of java.util.zip.ZipInputStream in project camel by apache.

the class ZipAggregationStrategyEmptyFileTest method testEmptyFile.

@Test
public void testEmptyFile() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:aggregateToZipEntry");
    mock.expectedMessageCount(1);
    template.sendBody("file:target/foo", "Hello");
    // empty file which is not aggregated
    template.sendBody("file:target/foo", "");
    template.sendBody("file:target/foo", "Bye");
    template.sendBody("file:target/foo", "Howdy");
    assertMockEndpointsSatisfied();
    Thread.sleep(500);
    File[] files = new File("target/out").listFiles();
    assertTrue(files != null);
    assertTrue("Should be a file in target/out directory", files.length > 0);
    File resultFile = files[0];
    ZipInputStream zin = new ZipInputStream(new FileInputStream(resultFile));
    try {
        int fileCount = 0;
        for (ZipEntry ze = zin.getNextEntry(); ze != null; ze = zin.getNextEntry()) {
            fileCount = fileCount + 1;
        }
        assertEquals("Zip file should contains " + ZipAggregationStrategyEmptyFileTest.EXPECTED_NO_FILES + " files", ZipAggregationStrategyEmptyFileTest.EXPECTED_NO_FILES, fileCount);
    } finally {
        IOHelper.close(zin);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) FileInputStream(java.io.FileInputStream) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)354 ZipEntry (java.util.zip.ZipEntry)259 FileInputStream (java.io.FileInputStream)120 File (java.io.File)115 IOException (java.io.IOException)103 ByteArrayInputStream (java.io.ByteArrayInputStream)63 FileOutputStream (java.io.FileOutputStream)63 ByteArrayOutputStream (java.io.ByteArrayOutputStream)62 Test (org.junit.Test)56 InputStream (java.io.InputStream)53 BufferedInputStream (java.io.BufferedInputStream)47 ZipOutputStream (java.util.zip.ZipOutputStream)31 FileNotFoundException (java.io.FileNotFoundException)21 Path (java.nio.file.Path)20 HashMap (java.util.HashMap)19 BufferedOutputStream (java.io.BufferedOutputStream)18 ArrayList (java.util.ArrayList)18 ZipFile (java.util.zip.ZipFile)18 OutputStream (java.io.OutputStream)17 GZIPInputStream (java.util.zip.GZIPInputStream)14