@Override public BZip2CompressorInputStream create(InputStream in) throws IOException { return new BZip2CompressorInputStream(in); }
@Override protected InputStream createInputStream(InputStream in) throws IOException { return new BZip2CompressorInputStream(in); } };
@Override InputStream decode(final String archiveName, final InputStream in, final long uncompressedLength, final Coder coder, final byte[] password) throws IOException { return new BZip2CompressorInputStream(in); } @Override
@Signature public void __construct(Environment env, InputStream inputStream, boolean decompressConcatenated) throws IOException { this.inputStream = new BZip2CompressorInputStream(inputStream, decompressConcatenated); } }
public static byte[] decompress(byte[] bytes, int len) throws IOException { byte[] data = new byte[len + BZIP_HEADER.length]; // add header System.arraycopy(BZIP_HEADER, 0, data, 0, BZIP_HEADER.length); System.arraycopy(bytes, 0, data, BZIP_HEADER.length, len); ByteArrayOutputStream os = new ByteArrayOutputStream(); try (InputStream is = new BZip2CompressorInputStream(new ByteArrayInputStream(data))) { IOUtils.copy(is, os); } return os.toByteArray(); } }
@Override public ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.array(), computeOffset(compressedData), compressedData.remaining()); try(BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int readCount = -1; while ((readCount = inputStream.read(buffer, compressedData.position(), buffer.length)) > 0) { baos.write(buffer, 0, readCount); } return ByteBuffer.wrap(baos.toByteArray()); } }
FileInputStream in = new FileInputStream("archive.tar.bz2"); FileOutputStream out = new FileOutputStream("archive.tar"); BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in); final byte[] buffer = new byte[buffersize]; int n = 0; while (-1 != (n = bzIn.read(buffer))) { out.write(buffer, 0, n); } out.close(); bzIn.close();
@Override public InputStreamWithHints openNextWithHints() throws IOException { if (!files.nextFile()) { return null; } return new InputStreamWithHints( new BZip2CompressorInputStream(files, true), fileInput.hintOfCurrentInputFileNameForLogging().orElse(null) ); }
@Override public ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.array()); BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int readCount = -1; while ( (readCount = inputStream.read(buffer, compressedData.position(), buffer.length))> 0) { baos.write(buffer, 0, readCount); } ByteBuffer result = ByteBuffer.wrap(baos.toByteArray()); return result; } finally { inputStream.close(); } }
@Override ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.array()); BZip2CompressorInputStream inputStream = new BZip2CompressorInputStream(bais); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int readCount = -1; while ( (readCount = inputStream.read(buffer, compressedData.position(), buffer.length))> 0) { baos.write(buffer, 0, readCount); } ByteBuffer result = ByteBuffer.wrap(baos.toByteArray()); return result; } finally { inputStream.close(); } }
@Override public void readOSM(OpenStreetMapContentHandler handler) { try { OpenStreetMapParser parser = new OpenStreetMapParser(); if (path.getName().endsWith(".gz")) { InputStream in = new GZIPInputStream(new FileInputStream(path)); parser.parseMap(in, handler); } else if (path.getName().endsWith(".bz2")) { BZip2CompressorInputStream in = new BZip2CompressorInputStream(new FileInputStream(path)); parser.parseMap(in, handler); } else { parser.parseMap(path, handler); } } catch (Exception ex) { throw new IllegalStateException("error loading OSM from path " + path, ex); } }
@Override public byte[] inflate(InputStream data) throws CompressionException { ByteArrayOutputStream out = new ByteArrayOutputStream(); BZip2CompressorInputStream bzip2 = null; try { bzip2 = new BZip2CompressorInputStream(data); IOUtils.copy(bzip2, out); } catch (IOException e) { throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e); } finally { if (bzip2 != null) { IOUtils.closeQuietly(bzip2); } } return out.toByteArray(); }
return gzipInputStream(in); } else if (fileName.endsWith(BZ2_SUFFIX)) { return new BZip2CompressorInputStream(in, true); } else if (fileName.endsWith(XZ_SUFFIX)) { return new XZCompressorInputStream(in, true);
public static void main(String[] args) throws IOException { if (args.length == 0) { throw new IllegalArgumentException("You need to specify the bz2 file!"); } String fromFile = args[0]; if (!fromFile.endsWith(".bz2")) { throw new IllegalArgumentException("You need to specify a bz2 file! But was:" + fromFile); } String toFile = Helper.pruneFileEnd(fromFile); FileInputStream in = new FileInputStream(fromFile); FileOutputStream out = new FileOutputStream(toFile); BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in); try { final byte[] buffer = new byte[1024 * 8]; int n = 0; while (-1 != (n = bzIn.read(buffer))) { out.write(buffer, 0, n); } } finally { out.close(); bzIn.close(); } } }
/** * open a compressed InputStream * @param in the InputStream to decompress * @return the InputStream to read from * @throws IOException if an I/O error occurs */ private InputStream openCompressedStream(InputStream in) throws IOException { if(mCurrentTask.compression==null) return in; switch(mCurrentTask.compression) { default: case none: return in; case gzip: return new GzipCompressorInputStream(in); case bzip: return new BZip2CompressorInputStream(in); case xz: return new XZCompressorInputStream(in); } }
@Override public void readOSM(OpenStreetMapContentHandler handler) { try { if (path.getName().endsWith(".gz")) { InputStream in = new GZIPInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 1); handler.doneFirstPhaseRelations(); in = new GZIPInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 2); handler.doneSecondPhaseWays(); in = new GZIPInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 3); handler.doneThirdPhaseNodes(); } else if (path.getName().endsWith(".bz2")) { InputStream in = new BZip2CompressorInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 1); handler.doneFirstPhaseRelations(); in = new BZip2CompressorInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 2); handler.doneSecondPhaseWays(); in = new BZip2CompressorInputStream(new FileInputStream(path)); StreamedOpenStreetMapParser.parseMap(in, handler, 3); handler.doneThirdPhaseNodes(); } else { StreamedOpenStreetMapParser.parseMap(path, handler); } } catch (Exception ex) { throw new IllegalStateException("error loading OSM from path " + path, ex); } }
private static File decompressTarBZ2(InputStream is) throws IOException { File outputDir = Files.createTempDir(); try (TarArchiveInputStream tais = new TarArchiveInputStream( new BZip2CompressorInputStream(is))) { TarArchiveEntry entry; while ((entry = tais.getNextTarEntry()) != null) { if (entry.isDirectory()) { continue; } File outputFile = new File(outputDir, entry.getName()); File parent = outputFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } try (FileOutputStream os = new FileOutputStream(outputFile)) { IOUtils.copy(tais, os); } } return outputDir; } }
return new BZip2CompressorInputStream(in, actualDecompressConcatenated);
try (BZip2CompressorInputStream bzin = new BZip2CompressorInputStream(new ByteArrayInputStream(bz2))) { final StringBuilder sb = new StringBuilder(); final byte[] buf = new byte[1024];
return new BZip2CompressorInputStream(is); case ENHANCED_DEFLATED: return new Deflate64CompressorInputStream(is);