Java Code Examples for java.util.zip.GZIPInputStream#skip()

The following examples show how to use java.util.zip.GZIPInputStream#skip() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GZIPInputStreamTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/** http://b/3042574 GzipInputStream.skip() causing CRC failures */
public void testSkip() throws IOException {
    byte[] data = new byte[1024 * 1024];
    byte[] gzipped = GZIPOutputStreamTest.gzip(data);
    GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(gzipped));
    long totalSkipped = 0;

    long count;
    do {
        count = in.skip(Long.MAX_VALUE);
        totalSkipped += count;
    } while (count > 0);

    assertEquals(data.length, totalSkipped);
    in.close();
}
 
Example 2
Source File: GZIPInZip.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 3
Source File: GZIPInZip.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 4
Source File: GZIPInZip.java    From native-obfuscator with GNU General Public License v3.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 5
Source File: GZIPInZip.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 6
Source File: GZIPInZip.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 7
Source File: GZIPInZip.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 8
Source File: GZIPInZip.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 9
Source File: GZIPInZip.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 10
Source File: GZIPInZip.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 11
Source File: GZIPInZip.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 12
Source File: GZIPInZip.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 13
Source File: GZIPInZip.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 14
Source File: GZIPInZip.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
Example 15
Source File: GZIPInZip.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}