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

Examples of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream$Data


     *
     * @return Contentinfo with contentType Data.
     */
    private ContentInfo makeData(SafeContents safe) throws IOException,
      ASN1Exception {
  Data data = null;
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  DEREncoder encoder = new DEREncoder(baos);
  safe.encode(encoder);
  data = new Data(baos.toByteArray());
  baos.close();
  ContentInfo cInfo = new ContentInfo(data);
  return cInfo;
    }
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

  // check version before any other operations
  Request request = new Request (display, major_opcode, 0, 3);
  request.write4 (CLIENT_MAJOR_VERSION);
  request.write4 (CLIENT_MINOR_VERSION);

  Data reply = display.read_reply (request);
  server_major_version = reply.read4 (8);
  server_minor_version = reply.read4 (12);
    }
View Full Code Here

     */
    public long getOverlayWindow (Window win) {
  Request request = new Request (display, major_opcode, 7, 2);
  request.write4 (win.id);

  Data reply = display.read_reply (request);
  if (reply == null) {
      return -1;
  }

  return reply.read4(8);
    }
View Full Code Here

    // check version before any other operations
    Request request = new Request (display, major_opcode, 0, 3);
    request.write4 (CLIENT_MAJOR_VERSION);
    request.write4 (CLIENT_MINOR_VERSION);
 
    Data reply = display.read_reply (request);
    server_major_version = reply.read2 (8);
    server_minor_version = reply.read2 (10);
  }
View Full Code Here

        // Stream buffer
        final int BUFF_SIZE = 8192;
        final byte[] buffer = new byte[BUFF_SIZE];

        BZip2CompressorInputStream inputStream = null;
        FileOutputStream outStream = null;

        try {
            FileInputStream is = new FileInputStream(in.getPath());
            inputStream = new BZip2CompressorInputStream(is);
            outStream = new FileOutputStream(out.getAbsolutePath());

            if (isTar) {
                // Read Tar header
                int remainingBytes = readTarHeader(inputStream);

                // Read content
                ByteBuffer bb = ByteBuffer.allocateDirect(4 * BUFF_SIZE);
                byte[] tmpCache = new byte[BUFF_SIZE];
                int nRead, nGet;
                while ((nRead = inputStream.read(tmpCache)) != -1) {
                    if (nRead == 0) {
                        continue;
                    }
                    bb.put(tmpCache);
                    bb.position(0);
                    bb.limit(nRead);
                    while (bb.hasRemaining() && remainingBytes > 0) {
                        nGet = Math.min(bb.remaining(), BUFF_SIZE);
                        nGet = Math.min(nGet, remainingBytes);
                        bb.get(buffer, 0, nGet);
                        outStream.write(buffer, 0, nGet);
                        remainingBytes -= nGet;
                    }
                    bb.clear();
                }
            } else {
                int len;
                while ((len = inputStream.read(buffer)) > 0) {
                    outStream.write(buffer, 0, len);
                }
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (outStream != null) {
                outStream.close();
            }
        }
View Full Code Here

        // Stream buffer
        final int BUFF_SIZE = 8192;
        final byte[] buffer = new byte[BUFF_SIZE];

        BZip2CompressorInputStream inputStream = null;
        FileOutputStream outStream = null;

        try {
            FileInputStream is = new FileInputStream(in.getPath());
            inputStream = new BZip2CompressorInputStream(is);
            outStream = new FileOutputStream(out.getAbsolutePath());

            if (isTar) {
                // Read Tar header
                int remainingBytes = readTarHeader(inputStream);

                // Read content
                ByteBuffer bb = ByteBuffer.allocateDirect(4 * BUFF_SIZE);
                byte[] tmpCache = new byte[BUFF_SIZE];
                int nRead, nGet;
                while ((nRead = inputStream.read(tmpCache)) != -1) {
                    if (nRead == 0) {
                        continue;
                    }
                    bb.put(tmpCache);
                    bb.position(0);
                    bb.limit(nRead);
                    while (bb.hasRemaining() && remainingBytes > 0) {
                        nGet = Math.min(bb.remaining(), BUFF_SIZE);
                        nGet = Math.min(nGet, remainingBytes);
                        bb.get(buffer, 0, nGet);
                        outStream.write(buffer, 0, nGet);
                        remainingBytes -= nGet;
                    }
                    bb.clear();
                }
            } else {
                int len;
                while ((len = inputStream.read(buffer)) > 0) {
                    outStream.write(buffer, 0, len);
                }
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (outStream != null) {
                outStream.close();
            }
        }
View Full Code Here

            throw new RuntimeException("Could not find " + inputFileName);
        }

        if (inputFile.getName().endsWith("bz2")) {
            FileInputStream fileInputStream = new FileInputStream(inputFile);
            in = new BZip2CompressorInputStream(fileInputStream);
        } else {
            randomAccessFile = new RandomAccessFile(inputFile, "r");
            in = new RandomAccessFileInputStream(randomAccessFile);
        }
View Full Code Here

        if(logMINOR) Logger.minor(this, "No compression");
        is = data.getInputStream();
        wrapper = null;
      } else if(ctype == COMPRESSOR_TYPE.BZIP2) {
        if(logMINOR) Logger.minor(this, "dealing with BZIP2");
        is = new BZip2CompressorInputStream(data.getInputStream());
        wrapper = null;
      } else if(ctype == COMPRESSOR_TYPE.GZIP) {
        if(logMINOR) Logger.minor(this, "dealing with GZIP");
        is = new GZIPInputStream(data.getInputStream());
        wrapper = null;
View Full Code Here

    }
  }
 
  @Override
  public long decompress(InputStream is, OutputStream os, long maxLength, long maxCheckSizeBytes) throws IOException, CompressionOutputSizeException {
    BZip2CompressorInputStream bz2is = new BZip2CompressorInputStream(HeaderStreams.augInput(BZ_HEADER, is));
    long written = 0;
    int bufSize = 32768;
    if(maxLength > 0 && maxLength < bufSize)
      bufSize = (int)maxLength;
    byte[] buffer = new byte[bufSize];
    while(true) {
      int expectedBytesRead = (int) Math.min(buffer.length, maxLength - written);
      // We can over-read to determine whether we have over-read.
      // We enforce maximum size this way.
      // FIXME there is probably a better way to do this!
      int bytesRead = bz2is.read(buffer, 0, buffer.length);
      if(expectedBytesRead < bytesRead) {
        Logger.normal(this, "expectedBytesRead="+expectedBytesRead+", bytesRead="+bytesRead+", written="+written+", maxLength="+maxLength+" throwing a CompressionOutputSizeException");
        if(maxCheckSizeBytes > 0) {
          written += bytesRead;
          while(true) {
            expectedBytesRead = (int) Math.min(buffer.length, maxLength + maxCheckSizeBytes - written);
            bytesRead = bz2is.read(buffer, 0, expectedBytesRead);
            if(bytesRead <= -1) throw new CompressionOutputSizeException(written);
            if(bytesRead == 0) throw new IOException("Returned zero from read()");
            written += bytesRead;
          }
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream$Data

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.