List of usage examples for org.apache.commons.compress.compressors.zstandard ZstdCompressorInputStream ZstdCompressorInputStream
public ZstdCompressorInputStream(final InputStream in) throws IOException
From source file:com.facebook.buck.step.fs.ZstdStepTest.java
@Test public void testZstdStep() throws Exception { Path sourceFileOriginal = TestDataHelper.getTestDataScenario(this, "compression_test").resolve("step.data"); Path sourceFile = tmp.newFile("step.data").toPath(); Files.copy(sourceFileOriginal, sourceFile, StandardCopyOption.REPLACE_EXISTING); File destinationFile = tmp.newFile("step.data.zstd"); ZstdStep step = new ZstdStep(TestProjectFilesystems.createProjectFilesystem(tmp.getRoot().toPath()), sourceFile, destinationFile.toPath()); ExecutionContext context = TestExecutionContext.newInstance(); assertEquals(0, step.execute(context).getExitCode()); ByteSource original = PathByteSource.asByteSource(sourceFileOriginal); ByteSource decompressed = new ByteSource() { @Override/* ww w . j av a2 s . c om*/ public InputStream openStream() throws IOException { return new ZstdCompressorInputStream(new FileInputStream(destinationFile)); } }; assertFalse(Files.exists(sourceFile)); assertTrue("Decompressed file must be identical to original.", original.contentEquals(decompressed)); }
From source file:com.facebook.buck.artifact_cache.ArtifactUploaderTest.java
/** compressSavesExecutableBit asserts that compress()-ing an executable file stores the x bit. */ @Test/* ww w . j a v a2 s. co m*/ public void compressSavesExecutableBit() throws Exception { ProjectFilesystem fs = FakeProjectFilesystem.createJavaOnlyFilesystem("/"); Path out = fs.getRootPath().resolve("out"); Path file = fs.getRootPath().resolve("file"); fs.writeContentsToPath("foo", file); Files.setPosixFilePermissions(fs.getPathForRelativePath(file), ImmutableSet.of(PosixFilePermission.OWNER_EXECUTE)); // Compress ArtifactUploader.compress(fs, ImmutableList.of(file), out); // Decompress+unarchive, and check that the only file is an executable. try (TarArchiveInputStream fin = new TarArchiveInputStream( new ZstdCompressorInputStream(Files.newInputStream(out)))) { ArrayList<TarArchiveEntry> entries = new ArrayList<>(); TarArchiveEntry entry; while ((entry = fin.getNextTarEntry()) != null) { entries.add(entry); } assertThat(entries, Matchers.hasSize(1)); assertThat(MorePosixFilePermissions.fromMode(entries.get(0).getMode()), Matchers.contains(PosixFilePermission.OWNER_EXECUTE)); } }
From source file:org.apache.avro.file.ZstandardCodec.java
@Override public ByteBuffer decompress(ByteBuffer compressedData) throws IOException { ByteArrayOutputStream baos = getOutputBuffer(compressedData.remaining()); InputStream bytesIn = new ByteArrayInputStream(compressedData.array(), compressedData.arrayOffset() + compressedData.position(), compressedData.remaining()); InputStream ios = new ZstdCompressorInputStream(bytesIn); try {//from w w w .j av a 2 s.c o m IOUtils.copy(ios, baos); } finally { ios.close(); } return ByteBuffer.wrap(baos.toByteArray()); }
From source file:org.apache.druid.java.util.common.CompressionUtils.java
/** * Decompress an input stream from a file, based on the filename. *//* w ww .j a v a2 s .c o m*/ public static InputStream decompress(final InputStream in, final String fileName) throws IOException { if (fileName.endsWith(GZ_SUFFIX)) { return gzipInputStream(in); } else if (fileName.endsWith(BZ2_SUFFIX)) { 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); } else if (fileName.endsWith(ZSTD_SUFFIX)) { return new ZstdCompressorInputStream(in); } else if (fileName.endsWith(ZIP_SUFFIX)) { // This reads the first file in the archive. final ZipInputStream zipIn = new ZipInputStream(in, StandardCharsets.UTF_8); try { final ZipEntry nextEntry = zipIn.getNextEntry(); if (nextEntry == null) { zipIn.close(); // No files in the archive - return an empty stream. return new ByteArrayInputStream(new byte[0]); } return zipIn; } catch (IOException e) { try { zipIn.close(); } catch (IOException e2) { e.addSuppressed(e2); } throw e; } } else { return in; } }