Package org.apache.commons.compress.compressors.bzip2

Examples of org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream


        try {
            int signatureLength = IOUtils.readFully(in, signature);
            in.reset();

            if (BZip2CompressorInputStream.matches(signature, signatureLength)) {
                return new BZip2CompressorInputStream(in, decompressConcatenated);
            }

            if (GzipCompressorInputStream.matches(signature, signatureLength)) {
                return new GzipCompressorInputStream(in, decompressConcatenated);
            }
View Full Code Here


            if (GZIP.equalsIgnoreCase(name)) {
                return new GzipCompressorInputStream(in, decompressConcatenated);
            }

            if (BZIP2.equalsIgnoreCase(name)) {
                return new BZip2CompressorInputStream(in, decompressConcatenated);
            }

            if (XZ.equalsIgnoreCase(name)) {
                return new XZCompressorInputStream(in, decompressConcatenated);
            }
View Full Code Here

                    if (compression == Compression.GZIP) {
                        in = new GZIPInputStream(in);
                    } else if (compression == Compression.XZ) {
                        in = new XZCompressorInputStream(in);
                    } else if (compression == Compression.BZIP2) {
                        in = new BZip2CompressorInputStream(in);
                    }
                   
                    ArchiveWalker.walk(new TarArchiveInputStream(in), new ArchiveVisitor<TarArchiveEntry>() {
                        public void visit(TarArchiveEntry entry, byte[] content) throws IOException {
                            found.set(true);
View Full Code Here

                    found.set(true);

                    assertEquals("header 0", (byte) 'B', content[0]);
                    assertEquals("header 1", (byte) 'Z', content[1]);

                    TarInputStream tar = new TarInputStream(new BZip2CompressorInputStream(new ByteArrayInputStream(content)));
                    while ((tar.getNextEntry()) != null) ;
                    tar.close();
                }
            }
        });
View Full Code Here

    public static InputSource getFileReader(String filename) throws FileNotFoundException, IOException {
        InputStream is;
        if (filename.endsWith(".xml.gz")) {
            is = new GZIPInputStream(new FileInputStream(filename));
        } else if (filename.endsWith(".xml.bz2")) {
            is = new BZip2CompressorInputStream(new FileInputStream(filename));
        } else if (filename.endsWith(".xml")) {
            is = new FileInputStream(filename);
        } else {
            System.err.println("Unsupported file: " + filename + ". Supported: *.xml.gz, *.xml.bz2, *.xml");
            System.exit(-1);
View Full Code Here

        byte[] compressed = new byte[out.readableBytes()];
        out.readBytes(compressed);
        out.release();

        ByteArrayInputStream is = new ByteArrayInputStream(compressed);
        BZip2CompressorInputStream bZip2Is = new BZip2CompressorInputStream(is);
        byte[] uncompressed = new byte[length];
        int remaining = length;
        while (remaining > 0) {
            int read = bZip2Is.read(uncompressed, length - remaining, remaining);
            if (read > 0) {
                remaining -= read;
            } else {
                break;
            }
        }

        assertEquals(-1, bZip2Is.read());

        return uncompressed;
    }
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

TOP

Related Classes of org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream

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.