Package java.util.zip

Examples of java.util.zip.DeflaterOutputStream


      assertTrue("Output doesn't match input",
          Arrays.equals("Foo\tBar\n".getBytes(), out.toByteArray()));
      out.reset();

      // Test deflate. Extension-based detection.
      OutputStream dout = new DeflaterOutputStream(
          fs.create(new Path(root, "file.deflate")));
      byte[] outbytes = "foo".getBytes();
      dout.write(outbytes);
      dout.close();
      out = new ByteArrayOutputStream();
      System.setOut(new PrintStream(out));
      argv = new String[2];
      argv[0] = "-text";
      argv[1] = new Path(root, "file.deflate").toString();
View Full Code Here


    out.resetCRC32();
    otp.setOffset(out.length());
    out.writeHeader(otp, ldr.getSize());

    deflater.reset();
    DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater);
    ldr.copyTo(dst);
    dst.finish();
  }
View Full Code Here

    TemporaryBuffer.Heap delta = delta(otp);
    out.writeHeader(otp, delta.length());

    Deflater deflater = deflater();
    deflater.reset();
    DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater);
    delta.writeTo(dst, null);
    dst.finish();
    typeStats.cntDeltas++;
    typeStats.deltaBytes += out.length() - otp.getOffset();
  }
View Full Code Here

      hdrBuf = new byte[32];
      md = Constants.newMessageDigest();
      crc32 = new CRC32();
      deflater = new Deflater(Deflater.BEST_COMPRESSION);
      compress = new DeflaterOutputStream(this, deflater, 8192);

      int size = out.blockSize();
      if (size <= 0)
        size = cache.getBlockSize();
      else if (size < cache.getBlockSize())
View Full Code Here

    out.resetCRC32();
    otp.setOffset(out.length());
    out.writeHeader(otp, ldr.getSize());

    deflater.reset();
    DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater);
    ldr.copyTo(dst);
    dst.finish();
  }
View Full Code Here

    TemporaryBuffer.Heap delta = delta(otp);
    out.writeHeader(otp, delta.length());

    Deflater deflater = deflater();
    deflater.reset();
    DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater);
    delta.writeTo(dst, null);
    dst.finish();
    typeStats.cntDeltas++;
    typeStats.deltaBytes += out.length() - otp.getOffset();
  }
View Full Code Here

   
    @Override
    protected final void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
            throws IOException
    {
        DeflaterOutputStream out = new DeflaterOutputStream(encoded);
        int amountRead;
        int mayRead = input.available();
        if (mayRead > 0)
        {
            byte[] buffer = new byte[Math.min(mayRead,BUFFER_SIZE)];
            while ((amountRead = input.read(buffer, 0, Math.min(mayRead,BUFFER_SIZE))) != -1)
            {
                out.write(buffer, 0, amountRead);
            }
        }
        out.close();
        encoded.flush();
    }
View Full Code Here

    boolean shouldStripGroup = heavySetup && Global.DSAgroupBigA.equals(cryptoGroup);
    if(shouldStripGroup)
      fs.removeSubset("dsaGroup");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeflaterOutputStream gis;
    gis = new DeflaterOutputStream(baos);
    try {
      fs.writeTo(gis);
                } catch (IOException e) {
                    Logger.error(this, "IOE :"+e.getMessage(), e);
    } finally {
View Full Code Here

  }

  private byte[] zipCompress(byte[] in) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(in.length);
    DeflaterOutputStream os = new DeflaterOutputStream(baos);
    try {
      os.write(in);
      os.finish();
      try {
        os.close();
      } catch (IOException e) {
        log.error("Close DeflaterOutputStream error", e);
      }
    } catch (IOException e) {
      throw new RuntimeException("IO exception compressing data", e);
View Full Code Here

    this.bytesPerPixel = (this.encodeAlpha) ? 4 : 3;

    final Deflater scrunch = new Deflater(this.compressionLevel);
    final ByteArrayOutputStream outBytes = new ByteArrayOutputStream(1024);
    final DeflaterOutputStream compBytes = new DeflaterOutputStream(outBytes, scrunch);
    try
    {
      int startRow = 0;       // starting row to process this time through
      //noinspection SuspiciousNameCombination
      int rowsLeft = this.height;  // number of rows remaining to write
      while (rowsLeft > 0)
      {
        final int nRows = Math.max(Math.min(32767 / (this.width * (this.bytesPerPixel + 1)), rowsLeft), 1);

        final int[] pixels = new int[this.width * nRows];

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

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

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

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

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

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

      /*
      * Write the compressed bytes
      */
      final byte[] compressedLines = outBytes.toByteArray();
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.