Java Code Examples for org.apache.commons.compress.compressors.CompressorInputStream#read()
The following examples show how to use
org.apache.commons.compress.compressors.CompressorInputStream#read() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompressTools.java From MyBox with Apache License 2.0 | 7 votes |
public static File decompress(CompressorInputStream compressorInputStream, File targetFile) { try { if (compressorInputStream == null) { return null; } File file = (targetFile == null) ? FileTools.getTempFile() : targetFile; if (file.exists()) { file.delete(); } try ( BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { final byte[] buf = new byte[CommonValues.IOBufferLength]; int len = -1; while (-1 != (len = compressorInputStream.read(buf))) { out.write(buf, 0, len); } } return file; } catch (Exception e) { // logger.debug(e.toString()); return null; } }
Example 2
Source File: CommonsCompressor.java From AutoLoadCache with Apache License 2.0 | 6 votes |
@Override public byte[] decompress(ByteArrayInputStream bais) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CompressorInputStream cis = FACTORY.createCompressorInputStream(name, bais); int len; byte buf[] = new byte[BUFFER]; while ((len = cis.read(buf, 0, BUFFER)) != -1) { baos.write(buf, 0, len); } cis.close(); byte[] output = baos.toByteArray(); baos.flush(); baos.close(); bais.close(); return output; }
Example 3
Source File: CommonsCompress.java From darks-codec with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void uncompress(InputStream input, OutputStream out) throws Exception { CompressorInputStream cin = null; try { cin = factory.createCompressorInputStream(type, input); byte[] buf = new byte[1024]; int len; while ((len = cin.read(buf)) > 0) { out.write(buf, 0, len); } out.flush(); } catch (CompressorException e) { throw new Exception( "Fail to decompress data by commons compress. Cause " + e.getMessage(), e); } finally { IoHelper.closeIO(cin); } }