Package com.dotcms.repackage.org.apache.commons.compress.compressors.bzip2

Examples of com.dotcms.repackage.org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream


            // gzip compression were used
            input = new GZIPInputStream(input);
        }
        else if(type.equals("application/x-bzip2")) {
            // bzip2 compression were used
            input = new BZip2CompressorInputStream(input);
        }
       
        return IOUtils.toString(input);
    }
View Full Code Here


          String compressor=Config.getStringProperty("CONTENT_METADATA_COMPRESSOR", "none");
          if(compressor.equals("gzip")) {
            out = new GZIPOutputStream(out);
          }
          else if(compressor.equals("bzip2")) {
            out = new BZip2CompressorOutputStream(out);
          }

          ReaderInputStream ris = null;

          try {
View Full Code Here

 
  @Override
  public long compress(InputStream is, OutputStream os, long maxReadLength, long maxWriteLength) throws IOException, CompressionOutputSizeException {
    if(maxReadLength <= 0)
      throw new IllegalArgumentException();
    BZip2CompressorOutputStream bz2os = null;
    try {
      CountedOutputStream cos = new CountedOutputStream(os);
      bz2os = new BZip2CompressorOutputStream(HeaderStreams.dimOutput(BZ_HEADER, cos));
      long read = 0;
      // Bigger input buffer, so can compress all at once.
      // Won't hurt on I/O either, although most OSs will only return a page at a time.
      byte[] buffer = new byte[32768];
      while(true) {
        int l = (int) Math.min(buffer.length, maxReadLength - read);
        int x = l == 0 ? -1 : is.read(buffer, 0, buffer.length);
        if(x <= -1) break;
        if(x == 0) throw new IOException("Returned zero from read()");
        bz2os.write(buffer, 0, x);
        read += x;
        if(cos.written() > maxWriteLength)
          throw new CompressionOutputSizeException();
      }
      bz2os.flush();
      cos.flush();
      bz2os.close();
      bz2os = null;
      if(cos.written() > maxWriteLength)
        throw new CompressionOutputSizeException();
      return cos.written();
    } finally {
      if(bz2os != null) {
        bz2os.flush();
        bz2os.close();
      }
     
    }
  }
View Full Code Here

    /**
     * @param stream the stream to write to, should be buffered
     */
    public CompressorOutputStream getCompressorStream(OutputStream stream)
        throws IOException {
        return new BZip2CompressorOutputStream(stream);
    }
View Full Code Here

   private byte[] compress(final byte[] uncompressedByteArray, Blob blob) throws IOException {
      //TODO go back to fully streamed version and get rid of the byte buffers
      final ByteArrayOutputStream baos = new ByteArrayOutputStream();

      InputStream input = new ByteArrayInputStream(uncompressedByteArray);
      BZip2CompressorOutputStream output = new BZip2CompressorOutputStream(baos);

      Streams.copy(input, output);

      output.close();
      input.close();

      final byte[] compressedByteArray = baos.toByteArray();

      blob.getMetadata().getContentMetadata().setContentMD5(getMd5Digest(compressedByteArray));
View Full Code Here

        }
        @Override
        OutputStream encode(final OutputStream out, final Object options)
                throws IOException {
            int blockSize = numberOptionOrDefault(options, BZip2CompressorOutputStream.MAX_BLOCKSIZE);
            return new BZip2CompressorOutputStream(out, blockSize);
        }
View Full Code Here

            if (GZIP.equalsIgnoreCase(name)) {
                return new GzipCompressorOutputStream(out);
            }

            if (BZIP2.equalsIgnoreCase(name)) {
                return new BZip2CompressorOutputStream(out);
            }

            if (XZ.equalsIgnoreCase(name)) {
                return new XZCompressorOutputStream(out);
            }
View Full Code Here

    /**
     * @param stream the stream to write to, should be buffered
     */
    public CompressorOutputStream getCompressorStream(OutputStream stream)
        throws IOException {
        return new BZip2CompressorOutputStream(stream);
    }
View Full Code Here

  public static final int DEFAULT_BUFFER_SIZE = 64 * 1024;
 
  @Override
  ByteBuffer compress(ByteBuffer uncompressedData) throws IOException {
    ByteArrayOutputStream baos = getOutputBuffer(uncompressedData.remaining());
    BZip2CompressorOutputStream outputStream = new BZip2CompressorOutputStream(baos);

    try {
      outputStream.write(uncompressedData.array());
    } finally {
      outputStream.close();
    }

    ByteBuffer result = ByteBuffer.wrap(baos.toByteArray());
    return result;
  }
View Full Code Here

            if (GZIP.equalsIgnoreCase(name)) {
                return new GzipCompressorOutputStream(out);
            }

            if (BZIP2.equalsIgnoreCase(name)) {
                return new BZip2CompressorOutputStream(out);
            }

            if (XZ.equalsIgnoreCase(name)) {
                return new XZCompressorOutputStream(out);
            }
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream

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.