Examples of Deflater


Examples of java.util.zip.Deflater

        Assert.assertEquals(0, inf1.available());
    }

    public void testNonContinuous() throws IOException {
        FastByteArrayOutputStream out = new FastByteArrayOutputStream(8192);
        DeflaterOutputStream def1 = new DeflaterOutputStream(out, new Deflater(Deflater.DEFAULT_COMPRESSION, false), 100);
        IOUtils.writeString("1", def1);
        IOUtils.writeInt(2, def1);
        IOUtils.writeString("3", def1);
        IOUtils.writeString("4", def1);
        IOUtils.writeString("5", def1);
View Full Code Here

Examples of java.util.zip.Deflater

      for(int j = 0 ; j<width ; j++) {
        payload[offset+j] = (byte)(127);
      }
    }
   
    Deflater deflater = new Deflater( Deflater.DEFAULT_COMPRESSION );
      ByteArrayOutputStream outBytes = new ByteArrayOutputStream((width+1)*height);
             
      DeflaterOutputStream compBytes = new DeflaterOutputStream( outBytes, deflater );
      try {
        compBytes.write(payload);
View Full Code Here

Examples of java.util.zip.Deflater

  private static int BLOCK_SIZE = 1000;
 
  public static ByteBuffer compressData(ByteBuffer inputData) {
   
    Deflater compressor = new Deflater();
   
    compressor.setInput(inputData.array());
    compressor.finish();
    long capacity = 0;
   
    int byte_count = 0;
   
    List<ByteBuffer> vector = new Vector<ByteBuffer>();
   
    do {
      ByteBuffer tmpData = Misc.getByteBuffer(BLOCK_SIZE);
     
      byte_count = compressor.deflate(tmpData.array());
   
      if (byte_count == 0) break;
     
      tmpData.limit(byte_count);
     
      vector.add(tmpData);
     
      capacity += byte_count;
     
    } while (byte_count != 0);
   
    compressor.end();
   
    ByteBuffer outputData = Misc.getByteBuffer(capacity);
   
    for(ByteBuffer buffer : vector) {
      buffer.position(0);
View Full Code Here

Examples of java.util.zip.Deflater

    */
   public void init(Global glob, AddressBase addressBase, PluginInfo pluginConfig)
         throws XmlBlasterException {
      this.addressBase = addressBase;
      this.pluginConfig = pluginConfig;
      this.compressor = new Deflater(Deflater.BEST_COMPRESSION);
      this.decompressor = new Inflater();

      // Add
      //   CbProtocolPlugin[email][1.0]=org.xmlBlaster.protocol.email.CallbackEmailDriver,mail.user=xmlBlaster,mail.password=xmlBlaster,compress/type=zlib:stream
      //   ClientCbServerProtocolPlugin[email][1.0]=org.xmlBlaster.client.protocol.email.EmailCallbackImpl,mail.user=demo,mail.password=demo,mail.pop3.url=pop3://demo:demo@localhost/INBOX,compress/type=zlib:stream
View Full Code Here

Examples of java.util.zip.Deflater

        super(out);
        this.minCompress=minCompress;
        buffer=new byte[MAXBUFFERSIZE];
        compBuffer=new byte[MAXBUFFERSIZE];
        writeIndex=0;
        deflater=new Deflater(Deflater.BEST_COMPRESSION);
    }
View Full Code Here

Examples of java.util.zip.Deflater

   }
  
   protected byte[] deflate(Object object) throws IOException
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      Deflater def = new Deflater(java.util.zip.Deflater.BEST_COMPRESSION);
      DeflaterOutputStream dos = new DeflaterOutputStream(baos, def);
     
      ObjectOutputStream out = new ObjectOutputStream(dos);
      out.writeObject(object);
      out.close();
View Full Code Here

Examples of java.util.zip.Deflater

 
  final void setOutputStream(int zlibCompressionLevel, OutputStream out) {
    if (zlibCompressionLevel > 0) {
      if (compressor == null || zlibCompressionLevel != compressionLevel) {
        if (compressor != null) compressor.end(); // free resources
        compressor = new Deflater(zlibCompressionLevel);
      }
    }
    compressionLevel = zlibCompressionLevel;
    this.out = out;
  }
View Full Code Here

Examples of java.util.zip.Deflater

            switch (compressionType) {

                case COMPRESSION_ZIP :
                    f = deflater = new DeflaterOutputStream(f,
                            new Deflater(Deflater.BEST_SPEED), b.length);
                    break;

                case COMPRESSION_GZIP :
                    f = deflater = new GZIPOutputStream(f, b.length);
                    break;
View Full Code Here

Examples of java.util.zip.Deflater

        PixelGrabber pg;

        bytesPerPixel = (encodeAlpha) ? 4 : 3;

        Deflater scrunch = new Deflater(compressionLevel);
        ByteArrayOutputStream outBytes = new ByteArrayOutputStream(1024);

        DeflaterOutputStream compBytes = new DeflaterOutputStream(outBytes, scrunch);
        try {
            while (rowsLeft > 0) {
                nRows = Math.min(32767 / (width * (bytesPerPixel + 1)), rowsLeft);
                nRows = Math.max( nRows, 1 );

                int[] pixels = new int[width * nRows];

                pg = new PixelGrabber(image, 0, startRow,
                    width, nRows, pixels, 0, width);
                try {
                    pg.grabPixels();
                }
                catch (Exception e) {
                    System.err.println("interrupted waiting for pixels!");
                    return false;
                }
                if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                    System.err.println("image fetch aborted or errored");
                    return false;
                }

                /*
                 * Create a data chunk. scanLines adds "nRows" for
                 * the filter bytes.
                 */
                scanLines = new byte[width * nRows * bytesPerPixel +  nRows];

                if (filter == FILTER_SUB) {
                    leftBytes = new byte[16];
                }
                if (filter == FILTER_UP) {
                    priorRow = new byte[width * bytesPerPixel];
                }

                scanPos = 0;
                startPos = 1;
                for (int i = 0; i < width * nRows; i++) {
                    if (i % width == 0) {
                        scanLines[scanPos++] = (byte) filter;
                        startPos = scanPos;
                    }
                    scanLines[scanPos++] = (byte) ((pixels[i] >> 16) & 0xff);
                    scanLines[scanPos++] = (byte) ((pixels[i] >>  8) & 0xff);
                    scanLines[scanPos++] = (byte) ((pixels[i]) & 0xff);
                    if (encodeAlpha) {
                        scanLines[scanPos++] = (byte) ((pixels[i] >> 24) & 0xff);
                    }
                    if ((i % width == width - 1) && (filter != FILTER_NONE)) {
                        if (filter == FILTER_SUB) {
                            filterSub(scanLines, startPos, width);
                        }
                        if (filter == FILTER_UP) {
                            filterUp(scanLines, startPos, width);
                        }
                    }
                }

                /*
                 * Write these lines to the output area
                 */
                compBytes.write(scanLines, 0, scanPos);

                startRow += nRows;
                rowsLeft -= nRows;
            }
            compBytes.close();

            /*
             * Write the compressed bytes
             */
            compressedLines = outBytes.toByteArray();
            nCompressed = compressedLines.length;

            crc.reset();
            bytePos = writeInt4(nCompressed, bytePos);
            bytePos = writeBytes(IDAT, bytePos);
            crc.update(IDAT);
            bytePos = writeBytes(compressedLines, nCompressed, bytePos);
            crc.update(compressedLines, 0, nCompressed);

            crcValue = crc.getValue();
            bytePos = writeInt4((int) crcValue, bytePos);
            scrunch.finish();
            return true;
        }
        catch (IOException e) {
            System.err.println(e.toString());
            return false;
View Full Code Here

Examples of java.util.zip.Deflater

    // TYPE_USHORT_GRAY    = 11
    // TYPE_USHORT_565_RGB = 8
    // TYPE_USHORT_555_RGB = 9
    // TYPE_CUSTOM         = 0.

        Deflater scrunch = new Deflater( compressionLevel );
        ByteArrayOutputStream outBytes =
            new ByteArrayOutputStream(1024);
           
        DeflaterOutputStream compBytes =
            new DeflaterOutputStream( outBytes, scrunch );

        if (bytesPerPixel == 1)
        {
            writePalette( (IndexColorModel) image.getColorModel() );
        }

        try
        {
            while (rowsLeft > 0)
            {
                nRows = Math.min( 32767 / (width*(bytesPerPixel+1)), rowsLeft );
                nRows = Math.max( nRows, 1 );

                /*
                 * Create a data chunk. scanLines adds "nRows" for
                 * the filter bytes.
                 */
                scanLines = new byte[width * nRows * bytesPerPixel +  nRows];

                if (filter == FILTER_SUB)
                {
                    leftBytes = new byte[16];
                }
                if (filter == FILTER_UP)
                {
                    priorRow = new byte[width*bytesPerPixel];
                }

        final Object data =
          wRaster.getDataElements( 0, startRow, width, nRows, null );

                pixels = null;
        iPixels = null;
        sPixels = null;
        if (tType == DataBuffer.TYPE_BYTE)
                {
                    pixels = (byte[]) data;
                }
                else if (tType == DataBuffer.TYPE_INT)
                {
                    iPixels = (int[]) data;
        }
        else if (tType == DataBuffer.TYPE_USHORT)
        {
          sPixels = (short[]) data;
        }

                scanPos = 0;
                readPos = 0;
                startPos = 1;
                for (int i=0; i<width*nRows; i++)
                {
                    if (i % width == 0)
                    {
                        scanLines[scanPos++] = (byte) filter;
                        startPos = scanPos;
                    }

                    if (bytesPerPixel == 1// assume TYPE_BYTE, indexed
                    {
                        scanLines[scanPos++] = pixels[readPos++];
                    }
                    else if (tType == DataBuffer.TYPE_BYTE)
                    {
                        scanLines[scanPos++] = pixels[readPos++];
                        scanLines[scanPos++] = pixels[readPos++];
                        scanLines[scanPos++] = pixels[readPos++];
                        if (encodeAlpha)
                        {
                            scanLines[scanPos++] = pixels[readPos++];
                        }
                        else
                        {
                            readPos++;
                        }
                    }
          else if (tType == DataBuffer.TYPE_USHORT)
          {
            short pxl = sPixels[readPos++];
            if (type == BufferedImage.TYPE_USHORT_565_RGB) {
              scanLines[scanPos++] = (byte) ((pxl >> 8) & 0xf8);
              scanLines[scanPos++] = (byte) ((pxl >> 2) & 0xfc);
            } else {                // assume USHORT_555_RGB
              scanLines[scanPos++] = (byte) ((pxl >> 7) & 0xf8);
              scanLines[scanPos++] = (byte) ((pxl >> 2) & 0xf8);
            }
            scanLines[scanPos++] = (byte) ((pxl << 3) & 0xf8);
          }
          else      // assume tType INT and type RGB or ARGB
          {
            int pxl = iPixels[readPos++];
            scanLines[scanPos++] = (byte) ((pxl >> 16) & 0xff);
            scanLines[scanPos++] = (byte) ((pxl >>  8) & 0xff);
            scanLines[scanPos++] = (byte) ((pxl      ) & 0xff);
            if (encodeAlpha) {
              scanLines[scanPos++] = (byte) ((pxl >> 24) & 0xff);
            }
          }

                    if ((i % width == width-1) && (filter != FILTER_NONE))
                    {
                        if (filter == FILTER_SUB)
                        {
                            filterSub( scanLines, startPos, width );
                        }
                        if (filter == FILTER_UP)
                        {
                            filterUp( scanLines, startPos, width );
                        }
                    }
                }

                /*
                 * Write these lines to the output area
                 */
                compBytes.write( scanLines, 0, scanPos );

                startRow += nRows;
                rowsLeft -= nRows;
            }
            compBytes.close();

            /*
             * Write the compressed bytes
             */
            compressedLines = outBytes.toByteArray();
            nCompressed = compressedLines.length;

            crc.reset();
            bytePos = writeInt4( nCompressed, bytePos );
            bytePos = writeBytes( IDAT, bytePos );
            crc.update( IDAT );
            bytePos = writeBytes( compressedLines, nCompressed, bytePos );
            crc.update( compressedLines, 0, nCompressed );

            crcValue = crc.getValue();
            bytePos = writeInt4( (int) crcValue, bytePos );
            scrunch.finish();
            return true;
        }
        catch (IOException e)
        {
            System.err.println( e.toString());
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.