@Override public ByteBuffer compress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); try (OutputStream outputStream = new XZCompressorOutputStream(baos, compressionLevel)) { outputStream.write(data.array(), computeOffset(data), data.remaining()); } return ByteBuffer.wrap(baos.toByteArray()); }
/** * Compress a byte array into XZ blob. * * @param data byte array to compress * @return compressed blob */ public static byte[] xz(final byte[] data) throws IOException { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(data.length * 2); final XZCompressorOutputStream xzCompressorOutputStream = new XZCompressorOutputStream(byteArrayOutputStream); xzCompressorOutputStream.write(data); xzCompressorOutputStream.close(); return byteArrayOutputStream.toByteArray(); }
/** * Compress a byte array into XZ blob. * * @param data byte array to compress * @return compressed blob */ public static byte[] xz(final byte[] data) { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(data.length * 2); try (final XZCompressorOutputStream xzCompressorOutputStream = new XZCompressorOutputStream(byteArrayOutputStream)) { xzCompressorOutputStream.write(data); } catch (final IOException e) { throw new RuntimeIOException(e); } return byteArrayOutputStream.toByteArray(); }
@Override public void close() { try { if ( this.xzOut != null ) { this.xzOut.close(); xzOut = null; } } catch ( final IOException e ) { throw new ArchiverException( "Failure closing target.", e ); } }
@Override public ByteBuffer compress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); OutputStream ios = new XZCompressorOutputStream(baos, compressionLevel); writeAndClose(data, ios); return ByteBuffer.wrap(baos.toByteArray()); }
@Test public void testDecompressXz() throws IOException { final File tmpDir = temporaryFolder.newFolder("testDecompressXz"); final File xzFile = new File(tmpDir, testFile.getName() + ".xz"); Assert.assertFalse(xzFile.exists()); try (final OutputStream out = new XZCompressorOutputStream(new FileOutputStream(xzFile))) { ByteStreams.copy(new FileInputStream(testFile), out); } try (final InputStream inputStream = CompressionUtils.decompress(new FileInputStream(xzFile), xzFile.getName())) { assertGoodDataStream(inputStream); } }
return new XZCompressorOutputStream(out);
@Override public void compress() throws ArchiverException { try { xzOut = new XZCompressorOutputStream( bufferedOutputStream( fileOutputStream( getDestFile() ) ) ); compress( getSource(), xzOut ); } catch ( IOException ioe ) { throw new ArchiverException( "Problem creating xz " + ioe.getMessage(), ioe ); } }
private OutputStream compress( TarCompressionMethod tarCompressionMethod, final OutputStream ostream ) throws IOException { if ( TarCompressionMethod.gzip.equals( tarCompressionMethod ) ) { return Streams.bufferedOutputStream( new GZIPOutputStream( ostream ) ); } else if ( TarCompressionMethod.bzip2.equals( tarCompressionMethod ) ) { return new BZip2CompressorOutputStream( bufferedOutputStream( ostream ) ); } else if ( TarCompressionMethod.snappy.equals( tarCompressionMethod ) ) { return new SnappyOutputStream( bufferedOutputStream( ostream ) ); } else if ( TarCompressionMethod.xz.equals( tarCompressionMethod ) ) { return new XZCompressorOutputStream( bufferedOutputStream( ostream ) ); } return ostream; }
/** * @param stream the stream to write to, should be buffered */ @Override public CompressorOutputStream getCompressorStream(OutputStream stream) throws IOException { return new XZCompressorOutputStream(stream); } }
@Override public OutputStream getOutputStream(final OutputStream out) throws IOException { return new XZCompressorOutputStream(out, preset); }
@Override public CompressorOutputStream compressorOutputStream(OutputStream os) throws IOException { return new XZCompressorOutputStream(os); }
@Override public CompressorOutputStream compressorOutputStream(OutputStream os) throws IOException { return new XZCompressorOutputStream(os); }
@Override public CompressorOutputStream create(File compressedFile) throws IOException { OutputStream os = new FileOutputStream(compressedFile); try { return new XZCompressorOutputStream(os); } catch (IOException ioe) { try { os.close(); } catch (Exception e) {} throw ioe; } }
@Override public CompressorOutputStream create(File compressedFile) throws IOException { OutputStream os = new FileOutputStream(compressedFile); try { return new XZCompressorOutputStream(os); } catch (IOException ioe) { try { os.close(); } catch (Exception e) {} throw ioe; } }
public ArchiveOutputStream createArchiveOutputStream(OutputStream s) throws IOException { XZCompressorOutputStream out = new XZCompressorOutputStream(s); return tarFormat.createArchiveOutputStream(out); }
/** * @since 4.0 */ public ArchiveOutputStream createArchiveOutputStream(OutputStream s, Map<String, Object> o) throws IOException { XZCompressorOutputStream out = new XZCompressorOutputStream(s); return tarFormat.createArchiveOutputStream(out, o); }
@Override public ByteBuffer compress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); OutputStream ios = new XZCompressorOutputStream(baos, compressionLevel); writeAndClose(data, ios); return ByteBuffer.wrap(baos.toByteArray()); }
public ByteArrayOutputStream compress() throws IOException { BufferedInputStream in = new BufferedInputStream(input); ByteArrayOutputStream bos = new ByteArrayOutputStream(); CompressorOutputStream out = new XZCompressorOutputStream(bos); IOUtils.copy(in, out); in.close(); out.flush(); out.close(); return bos; }
os = new XZCompressorOutputStream(os);