List of usage examples for org.apache.commons.compress.bzip2 CBZip2OutputStream CBZip2OutputStream
public CBZip2OutputStream(final OutputStream output) throws IOException
From source file:ch.rgw.compress.CompEx.java
public static byte[] CompressBZ2(InputStream in) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[8192]; baos.write(buf, 0, 4); // Lnge des Originalstroms CBZip2OutputStream bzo = new CBZip2OutputStream(baos); int l;//from ww w .ja va 2s .c o m int total = 0; ; while ((l = in.read(buf, 0, buf.length)) != -1) { bzo.write(buf, 0, l); total += l; } bzo.close(); byte[] ret = baos.toByteArray(); // Die hchstwertigen 3 Bit als Typmarker setzen total &= 0x1fffffff; total |= BZIP2; BinConverter.intToByteArray(total, ret, 0); return ret; }
From source file:net.contrapunctus.rngzip.io.RNGZSettings.java
/** * Filter an output stream through a compressor, as specified by * cm. That is, if cm is <code>GZ</code>, this method will * return <code>new GZIPOutputStream(out)</code>. *///from w ww.j a v a2 s . c om public static OutputStream wrapOutput(OutputStream out, DataCompression cm) throws IOException { switch (cm) { case NONE: break; case GZ: out = new GZIPOutputStream(out); break; case BZ2: out = new CBZip2OutputStream(out); break; case LZMA: out = new LzmaOutputStream(out); break; case PPM: out = new ArithCodeOutputStream(out, new PPMModel(PPM_SMALL_LENGTH)); break; case PPMX: out = new ArithCodeOutputStream(out, new PPMModel(PPM_LARGE_LENGTH)); break; // here's how it would work for external stuff: //out = (OutputStream) externalInstance // ("org.apache.commons.compress.bzip2.CBZip2OutputStream", // OutputStream.class, out); //break; default: assert false; } return out; }
From source file:ch.rgw.tools.StringTool.java
/** * Eine Hashtable in ein komprimiertes Byte-Array umwandeln * //www.j a v a 2 s . c o m * @param hash * die Hashtable * @param compressMode * GLZ, HUFF, BZIP2 * @param ExtInfo * Je nach Kompressmode ntige zusatzinfo * @return das byte-Array mit der komprimierten Hashtable * @deprecated compressmode is always ZIP now. */ @SuppressWarnings("unchecked") @Deprecated public static byte[] flatten(final Hashtable hash, final int compressMode, final Object ExtInfo) { ByteArrayOutputStream baos = null; OutputStream os = null; ObjectOutputStream oos = null; try { baos = new ByteArrayOutputStream(hash.size() * 30); switch (compressMode) { case GUESS: case ZIP: os = new ZipOutputStream(baos); ((ZipOutputStream) os).putNextEntry(new ZipEntry("hash")); break; case BZIP: os = new CBZip2OutputStream(baos); break; case HUFF: os = new HuffmanOutputStream(baos, (HuffmanTree) ExtInfo, 0); break; case GLZ: os = new GLZOutputStream(baos, hash.size() * 30); break; default: os = baos; } oos = new ObjectOutputStream(os); oos.writeObject(hash); if (os != null) { os.close(); } baos.close(); return baos.toByteArray(); } catch (Exception ex) { ExHandler.handle(ex); return null; } }