Package java.util.zip

Examples of java.util.zip.DeflaterOutputStream


     * @throws IOException
     *             If there is an error compressing the stream.
     */
    public void encode(InputStream rawData, OutputStream result, COSDictionary options) throws IOException
    {
        DeflaterOutputStream out = new DeflaterOutputStream(result);
        byte[] buffer = new byte[BUFFER_SIZE];
        int amountRead = 0;
        while ((amountRead = rawData.read(buffer, 0, BUFFER_SIZE)) != -1)
        {
            out.write(buffer, 0, amountRead);
        }
        out.close();
        result.flush();
    }
View Full Code Here


        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();
View Full Code Here

    try {
      os = new TempOutputStream();

      Sha256OutputStream mOut = new Sha256OutputStream(os);
      DeflaterOutputStream gzOut = new DeflaterOutputStream(mOut);

      serializer.serialize(value, gzOut);

      gzOut.finish();
      mOut.close();

      byte[] hash = mOut.getDigest();

      HashKey valueHash = new HashKey(hash);
View Full Code Here

   
    try {
      os = new TempOutputStream();

      Sha256OutputStream mOut = new Sha256OutputStream(os);
      DeflaterOutputStream gzOut = new DeflaterOutputStream(mOut);

      serializer.serialize(value, gzOut);

      gzOut.finish();
      mOut.close();

      byte[] hash = mOut.getDigest();

      return hash;
View Full Code Here

            try {
                ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
                OutputStream os = bytesOut;
                if (Settings.enable_compression()) {
                    compressed = true;
                    os = new DeflaterOutputStream(os);
                }
                DataOutputStream dataOut = new DataOutputStream(os);
                ObjectOutputStream objOut = new ObjectOutputStream(dataOut);
                objOut.writeObject(object);
                objOut.flush();
View Full Code Here

            if (getContent() == null && !map.isEmpty()) {
                ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
                OutputStream os = bytesOut;
                if (Settings.enable_compression()) {
                    compressed = true;
                    os = new DeflaterOutputStream(os);
                }
                DataOutputStream dataOut = new DataOutputStream(os);
                MarshallingSupport.marshalPrimitiveMap(map, dataOut);
                dataOut.close();
                setContent(bytesOut.toBuffer());
View Full Code Here

        }
    }

    private void writeIDAT() throws IOException {
        IDATOutputStream ios = new IDATOutputStream(dataOutput, 8192);
        DeflaterOutputStream dos =
            new DeflaterOutputStream(ios, new Deflater(9));

        // Future work - don't convert entire image to a Raster
        Raster ras = image.getData();

        if (skipAlpha) {
            int numBands = ras.getNumBands() - 1;
            int[] bandList = new int[numBands];
            for (int i = 0; i < numBands; i++) {
                bandList[i] = i;
            }
            ras = ras.createChild(0, 0,
                                  ras.getWidth(), ras.getHeight(),
                                  0, 0,
                                  bandList);
        }

        if (interlace) {
            // Interlacing pass 1
            encodePass(dos, ras, 0, 0, 8, 8);
            // Interlacing pass 2
            encodePass(dos, ras, 4, 0, 8, 8);
            // Interlacing pass 3
            encodePass(dos, ras, 0, 4, 4, 8);
            // Interlacing pass 4
            encodePass(dos, ras, 2, 0, 4, 4);
            // Interlacing pass 5
            encodePass(dos, ras, 0, 2, 2, 4);
            // Interlacing pass 6
            encodePass(dos, ras, 1, 0, 2, 2);
            // Interlacing pass 7
            encodePass(dos, ras, 0, 1, 1, 2);
        } else {
            encodePass(dos, ras, 0, 0, 1, 1);
        }

        dos.finish();
        ios.flush();
    }
View Full Code Here

            // load the actual profile as bytes
            byte[] ICCProfileData = param.getICCProfileData();
            ByteArrayOutputStream iccDflStream = new ByteArrayOutputStream(ICCProfileData.length);
            // compress (deflate) the profile
            DeflaterOutputStream dfl = new DeflaterOutputStream(iccDflStream);
            dfl.write(ICCProfileData);
            dfl.finish();
       
            // write name
            cs.write(ICCProfileName, 0, length);
            // write null delimiter
            cs.writeByte(0);
            // write compression type (always 0)
            cs.writeByte(0);
            // write ICC data
            cs.write(iccDflStream.toByteArray());
            dfl.close();
       
            cs.writeToStream(dataOutput);
        }
    }
View Full Code Here

    len = filterPrintableLatin1(value);

                cs.write(0);
                cs.write(0);

                DeflaterOutputStream dos = new DeflaterOutputStream(cs);
                dos.write(value, 0, len);
                dos.finish();

                cs.writeToStream(dataOutput);
            }
        }
    }
View Full Code Here

            if (endpoint.getBinding() == SamlBinding.HTTP_Redirect) {
                byte[] responseBytes = SamlUtils.getDocumentAsString(message).getBytes("UTF-8");

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                Deflater deflater = new Deflater(Deflater.DEFLATED, true);
                DeflaterOutputStream deflaterStream = new DeflaterOutputStream(baos, deflater);
                deflaterStream.write(responseBytes);
                deflaterStream.finish();

                byte[] deflatedMsg = baos.toByteArray();
                String base64EncodedResponse = Base64.encodeBytes(deflatedMsg, Base64.DONT_BREAK_LINES);

                PrivateKey privateKey = null;
View Full Code Here

TOP

Related Classes of java.util.zip.DeflaterOutputStream

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.