/** * Are the classes required to support Zstandard compression available? * @return true if the classes required to support Zstandard compression are available */ public static boolean isZstdCompressionAvailable() { final CachedAvailability cachedResult = cachedZstdAvailability; if (cachedResult != CachedAvailability.DONT_CACHE) { return cachedResult == CachedAvailability.CACHED_AVAILABLE; } return internalIsZstdCompressionAvailable(); }
@Override public int read(final byte[] buf, final int off, final int len) throws IOException { final int ret = decIS.read(buf, off, len); count(ret); return ret; }
@Override public ByteBuffer compress(ByteBuffer data) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(data.remaining()); try (OutputStream outputStream = new ZstdCompressorOutputStream(baos)) { outputStream.write(data.array(), computeOffset(data), data.remaining()); } return ByteBuffer.wrap(baos.toByteArray()); }
if (!ZstdUtils.isZstdCompressionAvailable()) { throw new CompressorException("Zstandard compression is not available." + YOU_NEED_ZSTD_JNI); return new ZstdCompressorInputStream(in);
@Override public ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(compressedData.remaining()); InputStream bytesIn = new ByteArrayInputStream( compressedData.array(), computeOffset(compressedData), compressedData.remaining()); try (InputStream ios = new ZstdCompressorInputStream(bytesIn)) { IOUtils.copy(ios, baos); } return ByteBuffer.wrap(baos.toByteArray()); }
if (ZstdUtils.matches(signature, signatureLength)) { return ZSTANDARD;
if (!ZstdUtils.isZstdCompressionAvailable()) { throw new CompressorException("Zstandard compression is not available." + YOU_NEED_ZSTD_JNI); return new ZstdCompressorInputStream(in);
return new FramedSnappyCompressorInputStream(in); } else if (fileName.endsWith(ZSTD_SUFFIX)) { return new ZstdCompressorInputStream(in); } else if (fileName.endsWith(ZIP_SUFFIX)) {
@Test public void testDecompressZstd() throws IOException { final File tmpDir = temporaryFolder.newFolder("testDecompressZstd"); final File zstdFile = new File(tmpDir, testFile.getName() + ".zst"); Assert.assertFalse(zstdFile.exists()); try (final OutputStream out = new ZstdCompressorOutputStream(new FileOutputStream(zstdFile))) { ByteStreams.copy(new FileInputStream(testFile), out); } try (final InputStream inputStream = CompressionUtils.decompress(new FileInputStream(zstdFile), zstdFile.getName())) { assertGoodDataStream(inputStream); } }
/** * Whether to cache the result of the Zstandard 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 */ public static void setCacheZstdAvailablity(final boolean doCache) { if (!doCache) { cachedZstdAvailability = CachedAvailability.DONT_CACHE; } else if (cachedZstdAvailability == CachedAvailability.DONT_CACHE) { final boolean hasZstd = internalIsZstdCompressionAvailable(); cachedZstdAvailability = hasZstd ? CachedAvailability.CACHED_AVAILABLE : CachedAvailability.CACHED_UNAVAILABLE; } }
@Override public int read() throws IOException { final int ret = decIS.read(); count(ret == -1 ? 0 : 1); return ret; }
if (ZstdUtils.matches(signature, signatureLength)) { return ZSTANDARD;
return new FramedSnappyCompressorInputStream(in); } else if (fileName.endsWith(ZSTD_SUFFIX)) { return new ZstdCompressorInputStream(in); } else if (fileName.endsWith(ZIP_SUFFIX)) {
/** * Are the classes required to support Zstandard compression available? * @return true if the classes required to support Zstandard compression are available */ public static boolean isZstdCompressionAvailable() { final CachedAvailability cachedResult = cachedZstdAvailability; if (cachedResult != CachedAvailability.DONT_CACHE) { return cachedResult == CachedAvailability.CACHED_AVAILABLE; } return internalIsZstdCompressionAvailable(); }
@Override public int read(final byte[] buf, final int off, final int len) throws IOException { final int ret = decIS.read(buf, off, len); count(ret); return ret; }
/** * Whether to cache the result of the Zstandard 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 */ public static void setCacheZstdAvailablity(final boolean doCache) { if (!doCache) { cachedZstdAvailability = CachedAvailability.DONT_CACHE; } else if (cachedZstdAvailability == CachedAvailability.DONT_CACHE) { final boolean hasZstd = internalIsZstdCompressionAvailable(); cachedZstdAvailability = hasZstd ? CachedAvailability.CACHED_AVAILABLE : CachedAvailability.CACHED_UNAVAILABLE; } }
@Override public int read() throws IOException { final int ret = decIS.read(); count(ret == -1 ? 0 : 1); return ret; }