Package java.util.zip

Examples of java.util.zip.DeflaterInputStream


    /**
     * @tests DeflaterInputStream#markSupported()
     */
    public void testMarkSupported() throws IOException {
        DeflaterInputStream dis = new DeflaterInputStream(is);
        assertFalse(dis.markSupported());
        dis.close();
        assertFalse(dis.markSupported());
    }
View Full Code Here


    /**
     * @tests DeflaterInputStream#read()
     */
    public void testRead() throws IOException {
        DeflaterInputStream dis = new DeflaterInputStream(is);
        assertEquals(1, dis.available());
        assertEquals(120, dis.read());
        assertEquals(1, dis.available());
        assertEquals(156, dis.read());
        assertEquals(1, dis.available());
        assertEquals(243, dis.read());
        assertEquals(1, dis.available());
        dis.close();
        try {
            dis.read();
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
    }
View Full Code Here

     * @tests DeflaterInputStream#read(byte[],int,int)
     */
    public void testReadByteArrayIntInt() throws IOException {
        byte[] buf1 = new byte[256];
        byte[] buf2 = new byte[256];
        DeflaterInputStream dis = new DeflaterInputStream(is);
        assertEquals(23, dis.read(buf1, 0, 256));
        dis = new DeflaterInputStream(is);
        assertEquals(8, dis.read(buf2, 0, 256));
        is = new ByteArrayInputStream(testStr.getBytes("UTF-8"));
        dis = new DeflaterInputStream(is);
        assertEquals(1, dis.available());
        assertEquals(120, dis.read());
        assertEquals(1, dis.available());
        assertEquals(22, dis.read(buf2, 0, 256));
        assertEquals(1, dis.available());
        assertEquals(-1, dis.read());
        assertEquals(0, dis.available());
        try {
            dis.read(buf1, 0, 512);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        try {
            dis.read(null, 0, 0);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            dis.read(null, -1, 0);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            dis.read(null, -1, -1);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            dis.read(buf1, -1, -1);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        try {
            dis.read(buf1, 0, -1);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // expected
        }
        dis.close();
        try {
            dis.read(buf1, 0, 512);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        try {
            dis.read(buf1, 0, 1);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        try {
            dis.read(null, 0, 0);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        try {
            dis.read(null, -1, 0);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        try {
            dis.read(null, -1, -1);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        try {
            dis.read(buf1, -1, -1);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        try {
            dis.read(buf1, 0, -1);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests DeflaterInputStream#reset()
     */
    public void testReset() throws IOException {
        DeflaterInputStream dis = new DeflaterInputStream(is);
        try {
            dis.reset();
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        dis.close();
        try {
            dis.reset();
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests DeflaterInputStream#skip()
     */
    public void testSkip() throws IOException {
        byte[] buf = new byte[1024];
        DeflaterInputStream dis = new DeflaterInputStream(is);
        assertEquals(1, dis.available());
        dis.skip(1);
        assertEquals(1, dis.available());
        assertEquals(22, dis.read(buf, 0, 1024));
        assertEquals(1, dis.available());
        dis.skip(1);
        assertEquals(0, dis.available());
        is = new ByteArrayInputStream(testStr.getBytes("UTF-8"));
        dis = new DeflaterInputStream(is);
        assertEquals(1, dis.available());
        dis.skip(56);
        assertEquals(0, dis.available());
        assertEquals(-1, dis.read(buf, 0, 1024));
        try {
            dis.skip(-1);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
        assertEquals(0, dis.available());
        // can still skip
        dis.skip(1);
        dis.close();
        try {
            dis.skip(1);
            fail("should throw IOException");
        } catch (IOException e) {
            // expected
        }
        try {
            dis.skip(-1);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }

        is = new ByteArrayInputStream(testStr.getBytes("UTF-8"));
        dis = new DeflaterInputStream(is);
        assertEquals(23, dis.skip(Long.MAX_VALUE));
        assertEquals(0, dis.available());
    }
View Full Code Here

    /**
     * @tests DeflaterInputStream#DeflaterInputStream(InputStream)
     */
    public void testDeflaterInputStreamInputStream() {
        // ok
        new DeflaterInputStream(is);
        // fail
        try {
            new DeflaterInputStream(null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests DeflaterInputStream#DeflaterInputStream(InputStream,Deflater)
     */
    public void testDeflaterInputStreamInputStreamDeflater() {
        // ok
        new DeflaterInputStream(is, new Deflater());
        // fail
        try {
            new DeflaterInputStream(is, null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            new DeflaterInputStream(null, new Deflater());
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests DeflaterInputStream#DeflaterInputStream(InputStream,Deflater,int)
     */
    public void testDeflaterInputStreamInputStreamDeflaterInt() {
        // ok
        new DeflaterInputStream(is, new Deflater(), 1024);
        // fail
        try {
            new DeflaterInputStream(is, null, 1024);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            new DeflaterInputStream(null, new Deflater(), 1024);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            new DeflaterInputStream(is, new Deflater(), -1);
            fail("should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
        try {
            new DeflaterInputStream(null, new Deflater(), -1);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
        try {
            new DeflaterInputStream(is, null, -1);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
    }
View Full Code Here

   *
   * @throws IOException
   */
  @FunctionSpec(name = "zlibuncompress", returnType = "bytes", formalParameters = { "bytes", "bool" })
  public static byte[] zlibUncompress(final byte[] compressedData, final boolean skipHeader) throws IOException {
    final DeflaterInputStream i = new DeflaterInputStream(new ByteArrayInputStream(compressedData), new Deflater(Deflater.DEFAULT_COMPRESSION), 8192);

    try {
      final ByteArrayOutputStream o = new ByteArrayOutputStream(compressedData.length);

      try {
        final byte[] buf = new byte[4096];

        int len;
        while ((len = i.read(buf)) > 0)
          o.write(buf, 0, len);
      } finally {
        o.close();
      }

      return o.toByteArray();
    } finally {
      i.close();
    }
  }
View Full Code Here

        try {
            digester = new DigestInputStream(uncompressedCounter, MessageDigest.getInstance("SHA1"));
        } catch (NoSuchAlgorithmException e) {
            throw new IOException("Unable to initialize digest", e);
        }
        DeflaterInputStream deflateFilter = new DeflaterInputStream(digester, def);
        compressedCounter = new CountingInputStream(deflateFilter);
    }
View Full Code Here

TOP

Related Classes of java.util.zip.DeflaterInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.