Search in sources :

Example 6 with CBZip2OutputStream

use of org.apache.hadoop.io.compress.bzip2.CBZip2OutputStream in project SilverKing by Morgan-Stanley.

the class BZip2 method compress.

public byte[] compress(byte[] rawValue, int offset, int length) throws IOException {
    ByteArrayOutputStream baos;
    CBZip2OutputStream bzip2os;
    byte[] buf;
    int compressedLength;
    // Log.warning("rawValue.length ", rawValue.length);
    baos = new ByteArrayOutputStream(rawValue.length / bzip2InitFactor);
    baos.write(0x42);
    baos.write(0x5a);
    bzip2os = new CBZip2OutputStream(baos);
    bzip2os.write(rawValue, offset, length);
    bzip2os.flush();
    bzip2os.close();
    baos.flush();
    baos.close();
    buf = baos.toByteArray();
    // System.out.println(StringUtil.byteArrayToHexString(buf));
    compressedLength = buf.length;
    if (Log.levelMet(Level.FINE)) {
        Log.fine("rawValue.length: " + rawValue.length);
        Log.fine("buf.length: " + buf.length);
        Log.fine("compressedLength: " + compressedLength);
    }
    // System.out.println("\t"+ StringUtil.byteArrayToHexString(buf));
    return buf;
}
Also used : CBZip2OutputStream(org.apache.hadoop.io.compress.bzip2.CBZip2OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with CBZip2OutputStream

use of org.apache.hadoop.io.compress.bzip2.CBZip2OutputStream in project ant by apache.

the class BZip2 method pack.

/**
 * Compress the zipFile.
 */
protected void pack() {
    CBZip2OutputStream zOut = null;
    try {
        BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(zipFile.toPath()));
        bos.write('B');
        bos.write('Z');
        zOut = new CBZip2OutputStream(bos);
        zipResource(getSrcResource(), zOut);
    } catch (IOException ioe) {
        String msg = "Problem creating bzip2 " + ioe.getMessage();
        throw new BuildException(msg, ioe, getLocation());
    } finally {
        FileUtils.close(zOut);
    }
}
Also used : CBZip2OutputStream(org.apache.tools.bzip2.CBZip2OutputStream) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

CBZip2OutputStream (org.apache.tools.bzip2.CBZip2OutputStream)6 FileOutputStream (java.io.FileOutputStream)5 File (java.io.File)3 OutputStream (java.io.OutputStream)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 OsmStorageWriter (net.osmand.osm.io.OsmStorageWriter)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 LinkedHashMap (java.util.LinkedHashMap)1