Examples of Deflater


Examples of java.util.zip.Deflater

        String dictionary2 = "1234";

        byte[] outputNo = new byte[100];
        byte[] output1 = new byte[100];
        byte[] output2 = new byte[100];
        Deflater defDictNo = new Deflater(9);
        Deflater defDict1 = new Deflater(9);
        Deflater defDict2 = new Deflater(9);

        defDict1.setDictionary(dictionary1.getBytes());
        defDict2.setDictionary(dictionary2.getBytes());

        defDictNo.setInput(inputString.getBytes());
        defDict1.setInput(inputString.getBytes());
        defDict2.setInput(inputString.getBytes());

        defDictNo.finish();
        defDict1.finish();
        defDict2.finish();

        int dataLenNo = defDictNo.deflate(outputNo);
        int dataLen1 = defDict1.deflate(output1);
        int dataLen2 = defDict2.deflate(output2);

        boolean passNo1 = false;
        boolean passNo2 = false;
        boolean pass12 = false;
View Full Code Here

Examples of java.util.zip.Deflater

        byte[] output1 = new byte[100];
        byte[] output2 = new byte[100];
        byte[] output3 = new byte[100];

        Deflater defDict1 = new Deflater(9);
        Deflater defDict2 = new Deflater(9);
        Deflater defDict3 = new Deflater(9);

        defDict1.setDictionary(dictionary1.getBytes());
        defDict2.setDictionary(dictionary2.getBytes());
        defDict3.setDictionary(dictionary2.getBytes(), 4, 4);

        defDict1.setInput(inputString.getBytes());
        defDict2.setInput(inputString.getBytes());
        defDict3.setInput(inputString.getBytes());

        defDict1.finish();
        defDict2.finish();
        defDict3.finish();

        int dataLen1 = defDict1.deflate(output1);
        int dataLen2 = defDict2.deflate(output2);
        int dataLen3 = defDict3.deflate(output3);

        boolean pass12 = false;
        boolean pass23 = false;
        boolean pass13 = true;
View Full Code Here

Examples of java.util.zip.Deflater

    // creating the decompressed data
    byte outPutBuf[] = new byte[500];
    byte byteArray[] = { 1, 3, 4, 7, 8 };
    byte outPutInf[] = new byte[500];
    int x = 0;
    Deflater deflate = new Deflater(1);
    deflate.setInput(byteArray);
    while (!(deflate.needsInput())) {
      x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
    }
    deflate.finish();
    while (!(deflate.finished())) {
      x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
    }

    Inflater inflate = new Inflater();
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuf);
        }

        inflate.inflate(outPutInf);
      }
    } catch (DataFormatException e) {
      fail("Input to inflate is invalid or corrupted - getTotalIn");
    }
    // System.out.print(deflate.getTotalOut() + " " + inflate.getTotalIn());
    assertTrue(
        "the total byte in outPutBuf did not equal the byte returned in getTotalIn",
        inflate.getTotalIn() == deflate.getTotalOut());

    Inflater inflate2 = new Inflater();
    int offSet = 0;// seems only can start as 0
    int length = 4;
    try {
View Full Code Here

Examples of java.util.zip.Deflater

    // creating the decompressed data
    byte outPutBuf[] = new byte[500];
    byte byteArray[] = { 1, 3, 4, 7, 8 };
    int y = 0;
    int x = 0;
    Deflater deflate = new Deflater(1);
    deflate.setInput(byteArray);
    while (!(deflate.needsInput())) {
      x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
    }
    deflate.finish();
    while (!(deflate.finished())) {
      x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
    }

    Inflater inflate = new Inflater();
    byte outPutInf[] = new byte[500];
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuf);
        }

        y += inflate.inflate(outPutInf);
      }
    } catch (DataFormatException e) {
      fail("Input to inflate is invalid or corrupted - getTotalIn");
    }

    assertTrue(
        "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
        y == inflate.getTotalOut());
    assertTrue(
        "the total number of bytes to be compressed does not equal the total bytes decompressed",
        inflate.getTotalOut() == deflate.getTotalIn());

    // testing inflate(byte,int,int)
    inflate.reset();
    y = 0;
    int offSet = 0;// seems only can start as 0
    int length = 4;
    try {
      while (!(inflate.finished())) {
        if (inflate.needsInput()) {
          inflate.setInput(outPutBuf);
        }

        y += inflate.inflate(outPutInf, offSet, length);
      }
    } catch (DataFormatException e) {
      System.out
          .println("Input to inflate is invalid or corrupted - getTotalIn");
    }
    assertTrue(
        "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
        y == inflate.getTotalOut());
    assertTrue(
        "the total number of bytes to be compressed does not equal the total bytes decompressed",
        inflate.getTotalOut() == deflate.getTotalIn());
  }
View Full Code Here

Examples of java.util.zip.Deflater

        0, outPutInf[byteArray.length]);
    // testing for an empty input array
    byte outPutBuf[] = new byte[500];
    byte emptyArray[] = new byte[11];
    int x = 0;
    Deflater defEmpty = new Deflater(3);
    defEmpty.setInput(emptyArray);
    while (!(defEmpty.needsInput())) {
      x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
    }
    defEmpty.finish();
    while (!(defEmpty.finished())) {
      x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
    }
    assertTrue(
        "the total number of byte from deflate did not equal getTotalOut - inflate(byte)",
        x == defEmpty.getTotalOut());
    assertTrue(
        "the number of input byte from the array did not correspond with getTotalIn - inflate(byte)",
        defEmpty.getTotalIn() == emptyArray.length);
    Inflater infEmpty = new Inflater();
    try {
      while (!(infEmpty.finished())) {
        if (infEmpty.needsInput()) {
          infEmpty.setInput(outPutBuf);
View Full Code Here

Examples of java.util.zip.Deflater

     * @tests java.util.zip.Deflater#getBytesRead()
     */
    public void test_getBytesRead() throws DataFormatException,
            UnsupportedEncodingException {
        // Regression test for HARMONY-158
        Deflater def = new Deflater();
        Inflater inf = new Inflater();
        assertEquals(0, def.getTotalIn());
        assertEquals(0, def.getTotalOut());
        assertEquals(0, def.getBytesRead());
        // Encode a String into bytes
        String inputString = "blahblahblah??";
        byte[] input = inputString.getBytes("UTF-8");

        // Compress the bytes
        byte[] output = new byte[100];
        def.setInput(input);
        def.finish();
        def.deflate(output);
        inf.setInput(output);
        int compressedDataLength =inf.inflate(input);
        assertEquals(16, inf.getTotalIn());
        assertEquals(compressedDataLength, inf.getTotalOut());
        assertEquals(16, inf.getBytesRead());
View Full Code Here

Examples of java.util.zip.Deflater

    /**
     * @tests java.util.zip.Deflater#getBytesRead()
     */
    public void test_getBytesWritten() throws DataFormatException, UnsupportedEncodingException {
        // Regression test for HARMONY-158
        Deflater def = new Deflater();
        Inflater inf = new Inflater();
        assertEquals(0, def.getTotalIn());
        assertEquals(0, def.getTotalOut());
        assertEquals(0, def.getBytesWritten());
        // Encode a String into bytes
        String inputString = "blahblahblah??";
        byte[] input = inputString.getBytes("UTF-8");

        // Compress the bytes
        byte[] output = new byte[100];
        def.setInput(input);
        def.finish();
        def.deflate(output);
        inf.setInput(output);
        int compressedDataLength =inf.inflate(input);
        assertEquals(16, inf.getTotalIn());
        assertEquals(compressedDataLength, inf.getTotalOut());
        assertEquals(14, inf.getBytesWritten());
View Full Code Here

Examples of java.util.zip.Deflater

    private static final int WRITES_RESUMED = 1 << 3;
    private static final int CLOSED = 1 << 4;

    public DeflatingStreamSinkConduit(final ConduitFactory<StreamSinkConduit> conduitFactory, final HttpServerExchange exchange) {

        deflater = new Deflater(Deflater.DEFLATED, true);
        this.currentBuffer = exchange.getConnection().getBufferPool().allocate();
        this.exchange = exchange;
        this.conduitFactory = conduitFactory;
    }
View Full Code Here

Examples of java.util.zip.Deflater


    public void init() throws Exception {
        deflater_pool=new ArrayBlockingQueue<Deflater>(pool_size);
        for(int i=0; i < pool_size; i++) {
            deflater_pool.add(new Deflater(compression_level));
        }
        inflater_pool=new ArrayBlockingQueue<Inflater>(pool_size);
        for(int i=0; i < pool_size; i++) {
            inflater_pool.add(new Inflater());
        }
View Full Code Here

Examples of java.util.zip.Deflater

            int length=msg.getLength(); // takes offset/length (if set) into account
            if(length >= min_size) {
                byte[] payload=msg.getRawBuffer(); // here we get the ref so we can avoid copying
                byte[] compressed_payload=new byte[length];
                int compressed_size;
                Deflater deflater=null;
                try {
                    deflater=deflater_pool.take();
                    deflater.reset();
                    deflater.setInput(payload, msg.getOffset(), length);
                    deflater.finish();
                    deflater.deflate(compressed_payload);
                    compressed_size=deflater.getTotalOut();
                    byte[] new_payload=new byte[compressed_size];
                    System.arraycopy(compressed_payload, 0, new_payload, 0, compressed_size);
                    msg.setBuffer(new_payload);
                    msg.putHeader(name, new CompressHeader(length));
                    if(log.isTraceEnabled())
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.