use of org.apache.tools.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;
}
use of org.apache.tools.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);
}
}
Aggregations