@Override public XZCompressorInputStream create(InputStream in) throws IOException { return new XZCompressorInputStream(in, true); }
/** * Are the classes required to support XZ compression available? * @since 1.5 * @return true if the classes required to support XZ compression are available */ public static boolean isXZCompressionAvailable() { final CachedAvailability cachedResult = cachedXZAvailability; if (cachedResult != CachedAvailability.DONT_CACHE) { return cachedResult == CachedAvailability.CACHED_AVAILABLE; } return internalIsXZCompressionAvailable(); }
private static boolean internalIsXZCompressionAvailable() { try { XZCompressorInputStream.matches(null, 0); return true; } catch (final NoClassDefFoundError error) { return false; } }
@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()); }
if (!XZUtils.isXZCompressionAvailable()) { throw new CompressorException("XZ compression is not available." + YOU_NEED_XZ_JAVA); return new XZCompressorInputStream(in, actualDecompressConcatenated, memoryLimitInKb);
@Override public CompressionMode getEffectiveCompressionMode(String filename) { if (GzipUtils.isCompressedFilename(filename)) { return GZIP; } else if (XZUtils.isCompressedFilename(filename)) { return XZ; } else { return NONE; } }
@Override public int read() throws IOException { try { final int ret = in.read(); count(ret == -1 ? -1 : 1); return ret; } catch (org.tukaani.xz.MemoryLimitException e) { throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), e); } }
@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 ); } }
if (XZUtils.matches(signature, signatureLength)) { return XZ;
@Override public ByteBuffer decompress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); InputStream bytesIn = new ByteArrayInputStream( data.array(), computeOffset(data), data.remaining()); try (InputStream ios = new XZCompressorInputStream(bytesIn)) { IOUtils.copy(ios, baos); } return ByteBuffer.wrap(baos.toByteArray()); }
@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()); }
/** * Whether to cache the result of the XZ for Java check. * * <p>This defaults to {@code false} in an OSGi environment and {@code true} otherwise.</p> * @param doCache whether to cache the result * @since 1.9 */ public static void setCacheXZAvailablity(final boolean doCache) { if (!doCache) { cachedXZAvailability = CachedAvailability.DONT_CACHE; } else if (cachedXZAvailability == CachedAvailability.DONT_CACHE) { final boolean hasXz = internalIsXZCompressionAvailable(); cachedXZAvailability = hasXz ? CachedAvailability.CACHED_AVAILABLE // NOSONAR : CachedAvailability.CACHED_UNAVAILABLE; } }
@Override public int read(final byte[] buf, final int off, final int len) throws IOException { try { final int ret = in.read(buf, off, len); count(ret); return ret; } catch (org.tukaani.xz.MemoryLimitException e) { //convert to commons-compress MemoryLimtException throw new MemoryLimitException(e.getMemoryNeeded(), e.getMemoryLimit(), e); } }
@Override public ByteBuffer decompress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); InputStream bytesIn = new ByteArrayInputStream( data.array(), data.arrayOffset() + data.position(), data.remaining()); InputStream ios = new XZCompressorInputStream(bytesIn); try { IOUtils.copy(ios, baos); } finally { ios.close(); } 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); } }
/** * 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); } }
return new XZCompressorOutputStream(out);
return new BZip2CompressorInputStream(in, true); } else if (fileName.endsWith(XZ_SUFFIX)) { return new XZCompressorInputStream(in, true); } else if (fileName.endsWith(SNAPPY_SUFFIX)) { return new FramedSnappyCompressorInputStream(in);
@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 ); } }
public static @Nonnull XZCompressorInputStream getXZInputStream( InputStream in ) throws ArchiverException { try { return new XZCompressorInputStream( in ); } catch ( IOException ioe ) { throw new ArchiverException( "Trouble creating BZIP2 compressor, invalid file ?", ioe ); } }