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 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 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(); } }
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(); } } }
public String[] readRecordsDirectly(URL testFileUrl, boolean bzip) throws IOException { int MAX_DATA_SIZE = 1024 * 1024; byte[] data = new byte[MAX_DATA_SIZE]; FileInputStream fis = new FileInputStream(testFileUrl.getFile()); int count; if (bzip) { BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(fis); count = bzIn.read(data); bzIn.close(); } else { count = fis.read(data); } fis.close(); assertTrue("Test file data too big for buffer", count < data.length); return new String(data, 0, count, "UTF-8").split("\n"); }
public String[] readRecordsDirectly(URL testFileUrl, boolean bzip) throws IOException { int MAX_DATA_SIZE = 1024 * 1024; byte[] data = new byte[MAX_DATA_SIZE]; FileInputStream fis = new FileInputStream(testFileUrl.getFile()); int count; if (bzip) { BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(fis); count = bzIn.read(data); bzIn.close(); } else { count = fis.read(data); } fis.close(); assertTrue("Test file data too big for buffer", count < data.length); return new String(data, 0, count, "UTF-8").split("\n"); }
@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(); } }
public void extract(String input_f, String output_f){ int buffersize = 1024; FileInputStream in; try { in = new FileInputStream(input_f); FileOutputStream out = new FileOutputStream(output_f); BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in); final byte[] buffer = new byte[buffersize]; int n = 0; int total = 0; while (-1 != (n = bzIn.read(buffer))) { total += n; final int percentage=(int)(total*100/lenghtOfFile); YourActivity.this.runOnUiThread(new Runnable() { public void run() { // TODO Auto-generated method stub progressBar.setProgress(percentage); } }); out.write(buffer, 0, n); } out.close(); bzIn.close(); } catch (Exception e) { throw new Error(e.getMessage()); } }
blobLog.close(); compressedInputStream.close();
if (bzipIn != null) { try { bzipIn.close(); } catch (IOException ioe) { throw new CommandExecutionException(ioe.getMessage(), ioe);
@Override public int decompress(byte[] src, int srcOff, int srcLen, byte[] dst, int dstOff) throws InsufficientBufferException, DataCorruptionException { try { if (srcStream == null) { srcStream = new ReusableByteArrayInputStream(src, srcOff, srcLen); } else { srcStream.reuse(src, srcOff, srcLen); } BZip2CompressorInputStream decompressStream = new BZip2CompressorInputStream(srcStream); int decompressedLen = decompressStream.read(dst, dstOff, dst.length - dstOff); srcStream.close(); decompressStream.close(); if (decompressedLen < 0) { throw new DataCorruptionException("Fail to decompress, decompressedLen: " + decompressedLen); } return decompressedLen; } catch (IOException e) { throw new DataCorruptionException(e); } } }