Package java.util.zip

Examples of java.util.zip.Deflater


    }

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


        File tempFile = null;

        int nextIFDOffset = 0;
        boolean skipByte = false;

        Deflater deflater = null;
        int deflateLevel = Deflater.DEFAULT_COMPRESSION;

        boolean jpegRGBToYCbCr = false;

        if(compression == COMP_NONE) {
            // Determine the number of bytes of padding necessary between
            // the end of the IFD and the first data segment such that the
            // alignment of the data conforms to the specification (required
            // for uncompressed data only).
            int numBytesPadding = 0;
            if(sampleSize[0] == 16 && tileOffsets[0] % 2 != 0) {
                numBytesPadding = 1;
                tileOffsets[0]++;
            } else if(sampleSize[0] == 32 && tileOffsets[0] % 4 != 0) {
                numBytesPadding = (int)(4 - tileOffsets[0] % 4);
                tileOffsets[0] += numBytesPadding;
            }

            // Update the data offsets (which TIFFField stores by reference).
            for (int i = 1; i < numTiles; i++) {
                tileOffsets[i] = tileOffsets[i-1] + tileByteCounts[i-1];
            }

            if(!isLast) {
                // Determine the offset of the next IFD.
                nextIFDOffset = (int)(tileOffsets[0] + totalBytesOfData);

                // IFD offsets must be on a word boundary.
                if(nextIFDOffset % 2 != 0) {
                    nextIFDOffset++;
                    skipByte = true;
                }
            }

            // Write the IFD and field overflow before the image data.
            writeDirectory(ifdOffset, fields, nextIFDOffset);

            // Write any padding bytes needed between the end of the IFD
            // and the start of the actual image data.
            if(numBytesPadding != 0) {
                for(int padding = 0; padding < numBytesPadding; padding++) {
                    output.write((byte)0);
                }
            }
        } else {
            // If compressing, the cannot be written yet as the size of the
            // data segments is unknown.

            if((output instanceof SeekableOutputStream)) {
                // Simply seek to the first data segment position.
                ((SeekableOutputStream)output).seek(tileOffsets[0]);
            } else {
                // Cache the original OutputStream.
                outCache = output;

                try {
                    // Attempt to create a temporary file.
                    tempFile = File.createTempFile("jai-SOS-", ".tmp");
                    tempFile.deleteOnExit();
                    RandomAccessFile raFile =
                        new RandomAccessFile(tempFile, "rw");
                    output = new SeekableOutputStream(raFile);
                    // XXX Be sure that this file is deleted no matter how
                    // this method is exited!
                } catch(Exception e) {
                    tempFile = null;
                    // Allocate memory for the entire image data (!).
                    output = new ByteArrayOutputStream((int)totalBytesOfData);
                }
            }

            int bufSize = 0;
            switch(compression) {
            case COMP_GROUP3_1D:
                // This initial buffer size is based on an alternating 1-0
                // pattern generating the most bits when converted to code
                // words: 9 bits out for each pair of bits in. So the number
                // of bit pairs is determined, multiplied by 9, converted to
                // bytes, and a ceil() is taken to account for fill bits at the
                // end of each line.  The "2" addend accounts for the case
                // of the pattern beginning with black.  The buffer is intended
                // to hold only a single row.
                bufSize = (int)Math.ceil((((tileWidth + 1)/2)*9 + 2)/8.0);
                break;
            case COMP_GROUP3_2D:
            case COMP_GROUP4:
                // Calculate the maximum row as the G3-1D size plus the EOL,
                // multiply this by the number of rows in the tile, and add
                // 6 EOLs for the RTC (return to control).
                bufSize = (int)Math.ceil((((tileWidth + 1)/2)*9 + 2)/8.0);
                bufSize = tileHeight*(bufSize + 2) + 12;
                break;
            case COMP_PACKBITS:
                bufSize = (int)(bytesPerTile +
                                ((bytesPerRow+127)/128)*tileHeight);
                break;
            case COMP_JPEG_TTN2:
                bufSize = 0;

                // Set color conversion flag.
                if(imageType == TIFF_YCBCR &&
                   colorModel != null &&
                   colorModel.getColorSpace().getType() ==
                   ColorSpace.TYPE_RGB) {
                    jpegRGBToYCbCr = true;
                }
                break;
            case COMP_DEFLATE:
                bufSize = (int)bytesPerTile;
                deflater = new Deflater(encodeParam.getDeflateLevel());
                break;
            default:
                bufSize = 0;
            }
            if(bufSize != 0) {
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();
View Full Code Here

    @Test
    public void testDecompressZlib() throws IOException {

        String testString = "Teststring 123";
        byte[] buffer = new byte[100];
        Deflater deflater = new Deflater();

        deflater.setInput(testString.getBytes());
        deflater.finish();
        deflater.deflate(buffer);
        deflater.end();

        assertEquals(testString, Tools.decompressZlib(buffer));
    }
View Full Code Here

  }

  @Override
  public boolean compress(ByteBuffer in, ByteBuffer out,
                          ByteBuffer overflow) throws IOException {
    Deflater deflater = new Deflater(compressionLevel, true);
    int length = in.remaining();
    deflater.setInput(in.array(), in.arrayOffset() + in.position(), length);
    deflater.finish();
    int outSize = 0;
    int offset = out.arrayOffset() + out.position();
    while (!deflater.finished() && (length > outSize)) {
      int size = deflater.deflate(out.array(), offset, out.remaining());
      out.position(size + out.position());
      outSize += size;
      offset += size;
      // if we run out of space in the out buffer, use the overflow
      if (out.remaining() == 0) {
        if (overflow == null) {
          deflater.end();
          return false;
        }
        out = overflow;
        offset = out.arrayOffset() + out.position();
      }
    }
    deflater.end();
    return length > outSize;
  }
View Full Code Here

    EBinary b = bin.testBinary();
    if (b == null) {
      throw ERT.badarg(bin);
    }
   
    Deflater defl = new Deflater();
    BARR bos = new BARR();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos, defl);
   
    try {
      b.writeTo(dos);
View Full Code Here

        }
    }

    protected static byte[] encrypt(byte[] src) {
        try {
            Deflater compressor = new Deflater(Deflater.BEST_SPEED);
            byte[] compressed = new byte[src.length + 100];

            compressor.setInput(src);
            compressor.finish();

            int totalOut = compressor.deflate(compressed);
            byte[] zipsrc = new byte[totalOut];

            System.arraycopy(compressed, 0, zipsrc, 0, totalOut);
            compressor.end();

            return CODEC.encode(zipsrc);
        } catch (Exception e) {
            throw new FacesException("Error encode resource data", e);
        }
View Full Code Here

      }
     
      //这种模式下是否覆盖原文件参数无效,每次都会覆盖
      if (needCompress)
      {
        Deflater def = new Deflater(Deflater.BEST_SPEED, false);
     
        bwriter = new BufferedWriter(new OutputStreamWriter(new DeflaterOutputStream(
          new FileOutputStream(FileName), def), "GBK"));
      }
      else   
View Full Code Here

        return result;
    }

    private ByteArrayOutputStream deflate(byte[] inflatedImageData, int strategy, int compression) throws IOException {
        ByteArrayOutputStream deflatedOut = new ByteArrayOutputStream();
        Deflater deflater = new Deflater(compression);
        deflater.setStrategy(strategy);

        DeflaterOutputStream stream = new DeflaterOutputStream(deflatedOut, deflater);
        stream.write(inflatedImageData);
        stream.close();
View Full Code Here


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

TOP

Related Classes of java.util.zip.Deflater

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.