Package java.util.zip

Examples of java.util.zip.InflaterOutputStream


  }

  @Override
  ByteBuffer decompress(ByteBuffer data) throws IOException {
    ByteArrayOutputStream baos = getOutputBuffer(data.remaining());
    InflaterOutputStream ios = new InflaterOutputStream(baos, getInflater());
    writeAndClose(data, ios);
    ByteBuffer result = ByteBuffer.wrap(baos.toByteArray());
    return result;
  }
View Full Code Here


    /**
     * @tests java.util.zip.InflaterOutputStream#InflaterOutputStream(java.io.OutputStream)
     */
    public void test_ConstructorLjava_io_OutputStream() throws IOException {
        new InflaterOutputStream(os);

        try {
            new InflaterOutputStream(null);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests java.util.zip.InflaterOutputStream#InflaterOutputStream(java.io.OutputStream,Inflater)
     */
    public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Inflater() {
        new InflaterOutputStream(os, new Inflater());

        try {
            new InflaterOutputStream(null, new Inflater());
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            new InflaterOutputStream(os, null);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests java.util.zip.InflaterOutputStream#InflaterOutputStream(java.io.OutputStream,Inflater,int)
     */
    public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_InflaterI() {
        new InflaterOutputStream(os, new Inflater(), 20);

        try {
            new InflaterOutputStream(null, null, 10);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            new InflaterOutputStream(null, new Inflater(), -1);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            new InflaterOutputStream(os, null, -1);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            new InflaterOutputStream(null, null, -1);
            fail("Should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }

        try {
            new InflaterOutputStream(os, new Inflater(), 0);
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }

        try {
            new InflaterOutputStream(os, new Inflater(), -10000);
            fail("Should throw IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            // expected
        }
    }
View Full Code Here

    /**
     * @tests java.util.zip.InflaterOutputStream#close()
     */
    public void test_close() throws IOException {
        InflaterOutputStream ios = new InflaterOutputStream(os);
        ios.close();
        // multiple close
        ios.close();
    }
View Full Code Here

    /**
     * @tests java.util.zip.InflaterOutputStream#flush()
     */
    public void test_flush() throws IOException {
        InflaterOutputStream ios = new InflaterOutputStream(os);
        ios.close();
        try {
            ios.flush();
            fail("Should throw IOException");
        } catch (IOException e) {
            // expected
        }
       
        ios = new InflaterOutputStream(os);
        ios.flush();
        ios.flush();
    }
View Full Code Here

    /**
     * @tests java.util.zip.InflaterOutputStream#finish()
     */
    public void test_finish() throws IOException {
        InflaterOutputStream ios = new InflaterOutputStream(os);
        ios.close();
        try {
            ios.finish();
            fail("Should throw IOException");
        } catch (IOException e) {
            // expected
        }
       
        ios = new InflaterOutputStream(os);
        ios.finish();
        ios.finish();
        ios.flush();
        ios.flush();
        ios.finish();
       
        byte[] bytes1 = {10,20,30,40,50};
        Deflater defaultDeflater = new Deflater(Deflater.BEST_SPEED);
        defaultDeflater.setInput(bytes1);
        defaultDeflater.finish();
        int length1 = defaultDeflater.deflate(compressedBytes);
       
        byte[] bytes2 = {100,90,80,70,60};
        Deflater bestDeflater = new Deflater(Deflater.BEST_COMPRESSION );
        bestDeflater.setInput(bytes2);
        bestDeflater.finish();
        int length2 = bestDeflater.deflate(compressedBytes,length1,compressedBytes.length-length1);
       
        ios = new InflaterOutputStream(os);
        for (int i = 0; i < length1; i++) {
            ios.write(compressedBytes[i]);
        }
        ios.finish();
        ios.close();
       
        byte[] result = os.toByteArray();
        for(int i =0;i<bytes1.length; i++){
            assertEquals(bytes1[i],result[i]);
        }
       
        ios = new InflaterOutputStream(os);
        for (int i = length1; i < length2*2; i++) {
            ios.write(compressedBytes[i]);
        }
        ios.finish();
        ios.close();
       
        result = os.toByteArray();
        for(int i =0;i<bytes2.length; i++){
            assertEquals(bytes2[i],result[bytes1.length+i]);
        }
View Full Code Here

     */
    public void test_write_I() throws IOException {
        int length = compressToBytes(testString);

        // uncompress the data stored in the compressedBytes
        InflaterOutputStream ios = new InflaterOutputStream(os);
        for (int i = 0; i < length; i++) {
            ios.write(compressedBytes[i]);
        }

        String result = new String(os.toByteArray());
        assertEquals(testString, result);
    }
View Full Code Here

     * @tests java.util.zip.InflaterOutputStream#write(int)
     */
    public void test_write_I_Illegal() throws IOException {

        // write after close
        InflaterOutputStream ios = new InflaterOutputStream(os);
        ios.close();
        try {
            ios.write(-1);
            fail("Should throw IOException");
        } catch (IOException e) {
            // expected
        }
    }
View Full Code Here

     */
    public void test_write_$BII() throws IOException {
        int length = compressToBytes(testString);

        // uncompress the data stored in the compressedBytes
        InflaterOutputStream ios = new InflaterOutputStream(os);
        ios.write(compressedBytes, 0, length);

        String result = new String(os.toByteArray());
        assertEquals(testString, result);
    }
View Full Code Here

TOP

Related Classes of java.util.zip.InflaterOutputStream

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.