List of usage examples for org.apache.commons.compress.bzip2 CBZip2InputStream CBZip2InputStream
public CBZip2InputStream(final InputStream input)
From source file:ja.lingo.readers.sdictionary.compressor.Bzip2Compressor.java
public byte[] uncompress(byte[] bytes, int offset, int length) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream gzis = new CBZip2InputStream(new ByteArrayInputStream(bytes, offset, length)); byte[] buffer = new byte[32768]; int read;//from w w w . j a v a 2 s. c o m while ((read = gzis.read(buffer)) != -1) { baos.write(buffer, 0, read); } gzis.close(); return baos.toByteArray(); }
From source file:com.stratio.parsers.XMLDumpParser.java
/** * * Based on wikixmlj by Delip Rao and Jason Smith. * Licensed under the Apache License 2.0. * Available at http://code.google.com/p/wikixmlj/ * * @return/*w w w .j a v a2 s .c om*/ * @throws FileNotFoundException * @throws IOException */ protected InputSource getInputSource() throws FileNotFoundException, IOException { if (inStream != null) { return new InputSource(inStream); } FileInputStream fis = new FileInputStream(dumpFile); InputStream is; InputStreamReader isr; if (dumpFile.endsWith(".gz")) { is = new GZIPInputStream(fis); } else if (dumpFile.endsWith(".bz2")) { byte[] ignoreBytes = new byte[2]; fis.read(ignoreBytes); //"B", "Z" bytes from commandline tools is = new CBZip2InputStream(fis); } else { is = fis; } CharsetDecoder decoder = Charsets.UTF_8.newDecoder(); decoder.onUnmappableCharacter(CodingErrorAction.IGNORE); decoder.onMalformedInput(CodingErrorAction.IGNORE); decoder.replaceWith("?"); isr = new InputStreamReader(is, decoder); return new InputSource(isr); //return new InputSource(new BufferedReader(isr)); }
From source file:cc.creativecomputing.io.CCIOUtil.java
static public InputStream openStream(final String theFileName) { InputStream myResult = createStream(theFileName); if (myResult == null) throw new CCIOException("Could not open the given file:" + theFileName); String myExtension = fileExtension(theFileName); try {//ww w.jav a 2 s .co m if (myExtension.equals("bz2")) { int first = myResult.read(); int second = myResult.read(); if (first != 'B' || second != 'Z') throw new RuntimeException("Didn't find BZ file signature in .bz2 file"); return new CBZip2InputStream(myResult); } if (myExtension.equals("gz")) return new GZIPInputStream(myResult); return myResult; } catch (Exception e) { throw new RuntimeException("Could not open the given file:" + theFileName, e); } }
From source file:ch.rgw.compress.CompEx.java
public static byte[] expand(InputStream in) { ByteArrayOutputStream baos;//w ww.j a v a2 s.com byte[] siz = new byte[4]; try { in.read(siz); long size = BinConverter.byteArrayToInt(siz, 0); long typ = size & ~0x1fffffff; size &= 0x1fffffff; byte[] ret = new byte[(int) size]; switch ((int) typ) { case BZIP2: CBZip2InputStream bzi = new CBZip2InputStream(in); int off = 0; int l = 0; while ((l = bzi.read(ret, off, ret.length - off)) > 0) { off += l; } bzi.close(); in.close(); return ret; case GLZ: GLZ glz = new GLZ(); baos = new ByteArrayOutputStream(); glz.expand(in, baos); return baos.toByteArray(); case HUFF: HuffmanInputStream hin = new HuffmanInputStream(in); off = 0; l = 0; while ((l = hin.read(ret, off, ret.length - off)) > 0) { off += l; } hin.close(); return ret; case ZIP: ZipInputStream zi = new ZipInputStream(in); zi.getNextEntry(); off = 0; l = 0; while ((l = zi.read(ret, off, ret.length - off)) > 0) { off += l; } zi.close(); return ret; default: throw new Exception("Invalid compress format"); } } catch (Exception ex) { ExHandler.handle(ex); return null; } }
From source file:cc.creativecomputing.io.CCIOUtil.java
/** * decode a bzip input stream//from w ww . j av a 2 s . com */ static public InputStream bzipInput(InputStream input) { return new CBZip2InputStream(input); }
From source file:ch.rgw.tools.StringTool.java
/** * Ein mit flatten() erzeugtes Byte-Array wieder in eine HAshtable zurckverwandeln * /* w w w .j a v a2 s . c o m*/ * @param flat * Die komprimierte Hashtable * @param compressMode * Expnad-Modus * @param ExtInfo * @return die Hastbale */ @SuppressWarnings("unchecked") @Deprecated public static Hashtable fold(final byte[] flat, final int compressMode, final Object ExtInfo) { ObjectInputStream ois = null; try { ByteArrayInputStream bais = new ByteArrayInputStream(flat); switch (compressMode) { case BZIP: ois = new ObjectInputStream(new CBZip2InputStream(bais)); break; case HUFF: ois = new ObjectInputStream(new HuffmanInputStream(bais)); break; case GLZ: ois = new ObjectInputStream(new GLZInputStream(bais)); break; case ZIP: ZipInputStream zis = new ZipInputStream(bais); zis.getNextEntry(); ois = new ObjectInputStream(zis); break; case GUESS: Hashtable<Object, Object> res = fold(flat, ZIP, null); if (res == null) { res = fold(flat, GLZ, null); if (res == null) { res = fold(flat, BZIP, null); if (res == null) { res = fold(flat, HUFF, ExtInfo); if (res == null) { return null; } } } } return res; default: ois = new ObjectInputStream(bais); break; } Hashtable<Object, Object> res = (Hashtable<Object, Object>) ois.readObject(); ois.close(); bais.close(); return res; } catch (Exception ex) { // ExHandler.handle(ex); deliberately don't mind return null; } }
From source file:net.contrapunctus.rngzip.io.RNGZSettings.java
/** * Create a decompressing input stream, according to the value of * cm. //from ww w.j av a2s . c o m */ public static InputStream wrapInput(InputStream in, DataCompression cm) throws IOException { switch (cm) { case NONE: break; case GZ: in = new GZIPInputStream(in); break; case BZ2: in = new CBZip2InputStream(in); break; case LZMA: in = new LzmaInputStream(in); break; case PPM: in = new ArithCodeInputStream(in, new PPMModel(PPM_SMALL_LENGTH)); break; case PPMX: in = new ArithCodeInputStream(in, new PPMModel(PPM_LARGE_LENGTH)); break; default: assert false; } return in; }