/** * Gunzip from the input stream to the output file * * @param in The compressed input stream to read from * @param outFile The file to write the uncompressed results to * * @return A FileCopyResult of the file written */ public static FileUtils.FileCopyResult gunzip(final ByteSource in, File outFile) { return gunzip(in, outFile, FileUtils.IS_EXCEPTION); }
/** * gunzip the file to the output file. * * @param pulledFile The source of the gz data * @param outFile A target file to put the contents * * @return The result of the file copy * * @throws IOException */ public static FileUtils.FileCopyResult gunzip(final File pulledFile, File outFile) { return gunzip(Files.asByteSource(pulledFile), outFile); }
/** * Uncompress using a gzip uncompress algorithm from the `pulledFile` to the `outDir`. * Unlike `org.apache.druid.java.util.common.CompressionUtils.gunzip`, this function takes an output *DIRECTORY* and tries to guess the file name. * It is recommended that the caller use `org.apache.druid.java.util.common.CompressionUtils.gunzip` and specify the output file themselves to ensure names are as expected * * @param pulledFile The source file * @param outDir The destination directory to put the resulting file * * @throws IOException on propagated IO exception, IAE if it cannot determine the proper new name for `pulledFile` */ @Deprecated // See description for alternative public static void gunzip(File pulledFile, File outDir) { final File outFile = new File(outDir, org.apache.druid.java.util.common.CompressionUtils.getGzBaseName(pulledFile.getName())); org.apache.druid.java.util.common.CompressionUtils.gunzip(pulledFile, outFile); if (!pulledFile.delete()) { log.error("Could not delete tmpFile[%s].", pulledFile); } }
@Test // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7036144 public void testGunzipBugStreamWorkarround() throws IOException { final ByteArrayOutputStream tripleGzByteStream = new ByteArrayOutputStream(gzBytes.length * 3); tripleGzByteStream.write(gzBytes); tripleGzByteStream.write(gzBytes); tripleGzByteStream.write(gzBytes); try (ByteArrayOutputStream bos = new ByteArrayOutputStream(expected.length * 3)) { Assert.assertEquals( expected.length * 3, CompressionUtils.gunzip( new ZeroRemainingInputStream( new ByteArrayInputStream(tripleGzByteStream.toByteArray()) ), bos ) ); final byte[] found = bos.toByteArray(); Assert.assertEquals(expected.length * 3, found.length); Assert.assertArrayEquals(expected, Arrays.copyOfRange(found, expected.length * 0, expected.length * 1)); Assert.assertArrayEquals(expected, Arrays.copyOfRange(found, expected.length * 1, expected.length * 2)); Assert.assertArrayEquals(expected, Arrays.copyOfRange(found, expected.length * 2, expected.length * 3)); } }
final FileUtils.FileCopyResult result = CompressionUtils.gunzip( Files.asByteSource(sourceFile), outFile,
@Test public void testGoodGZCompressUncompressToFile() throws Exception { final File tmpDir = temporaryFolder.newFolder("testGoodGZCompressUncompressToFile"); final File gzFile = new File(tmpDir, testFile.getName() + ".gz"); Assert.assertFalse(gzFile.exists()); CompressionUtils.gzip(testFile, gzFile); Assert.assertTrue(gzFile.exists()); try (final InputStream inputStream = new GZIPInputStream(new FileInputStream(gzFile))) { assertGoodDataStream(inputStream); } testFile.delete(); Assert.assertFalse(testFile.exists()); CompressionUtils.gunzip(gzFile, testFile); Assert.assertTrue(testFile.exists()); try (final InputStream inputStream = new FileInputStream(testFile)) { assertGoodDataStream(inputStream); } }
@Test public void testGoodGZStream() throws IOException { final File tmpDir = temporaryFolder.newFolder("testGoodGZStream"); final File gzFile = new File(tmpDir, testFile.getName() + ".gz"); Assert.assertFalse(gzFile.exists()); CompressionUtils.gzip(new FileInputStream(testFile), new FileOutputStream(gzFile)); Assert.assertTrue(gzFile.exists()); try (final InputStream inputStream = new GZIPInputStream(new FileInputStream(gzFile))) { assertGoodDataStream(inputStream); } if (!testFile.delete()) { throw new IOE("Unable to delete file [%s]", testFile.getAbsolutePath()); } Assert.assertFalse(testFile.exists()); CompressionUtils.gunzip(new FileInputStream(gzFile), testFile); Assert.assertTrue(testFile.exists()); try (final InputStream inputStream = new FileInputStream(testFile)) { assertGoodDataStream(inputStream); } }
final File outFile = new File(outDir, fname); final FileUtils.FileCopyResult result = CompressionUtils.gunzip(byteSource, outFile, S3Utils.S3RETRY); log.info("Loaded %d bytes from [%s] to [%s]", result.size(), s3Coords.toString(), outFile.getAbsolutePath()); return result;
final FileUtils.FileCopyResult result = CompressionUtils.gunzip( new ByteSource()
Assert.assertEquals((long) (expected.length * 3), CompressionUtils.gunzip(inputStreamFactory, testFile).size());
@Override protected ListenableFuture<Response> go(Request request) throws IOException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( HttpHeaders.Values.GZIP, request.getHeaders().get(HttpHeaders.Names.CONTENT_ENCODING) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteBuffer data = request.getByteBufferData().slice(); byte[] dataArray = new byte[data.remaining()]; data.get(dataArray); CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos); Assert.assertEquals( StringUtils.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), baos.toString(StandardCharsets.UTF_8.name()) ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Test public void testGoodGzipByteSource() throws IOException { final File tmpDir = temporaryFolder.newFolder("testGoodGzipByteSource"); final File gzFile = new File(tmpDir, testFile.getName() + ".gz"); Assert.assertFalse(gzFile.exists()); CompressionUtils.gzip(Files.asByteSource(testFile), Files.asByteSink(gzFile), Predicates.alwaysTrue()); Assert.assertTrue(gzFile.exists()); try (final InputStream inputStream = CompressionUtils.decompress(new FileInputStream(gzFile), gzFile.getName())) { assertGoodDataStream(inputStream); } if (!testFile.delete()) { throw new IOE("Unable to delete file [%s]", testFile.getAbsolutePath()); } Assert.assertFalse(testFile.exists()); CompressionUtils.gunzip(Files.asByteSource(gzFile), testFile); Assert.assertTrue(testFile.exists()); try (final InputStream inputStream = new FileInputStream(testFile)) { assertGoodDataStream(inputStream); } }
CompressionUtils.gunzip( new FileInputStream(gzFile), new FilterOutputStream( new FileOutputStream(testFile)
CompressionUtils.gunzip(Files.asByteSource(gzFile), testFile); Assert.assertTrue(testFile.exists()); try (final InputStream inputStream = new FileInputStream(testFile)) {
/** * Gunzip from the input stream to the output file * * @param in The compressed input stream to read from * @param outFile The file to write the uncompressed results to * * @return A FileCopyResult of the file written */ public static FileUtils.FileCopyResult gunzip(final ByteSource in, File outFile) { return gunzip(in, outFile, FileUtils.IS_EXCEPTION); }
/** * gunzip the file to the output file. * * @param pulledFile The source of the gz data * @param outFile A target file to put the contents * * @return The result of the file copy * * @throws IOException */ public static FileUtils.FileCopyResult gunzip(final File pulledFile, File outFile) { return gunzip(Files.asByteSource(pulledFile), outFile); }
/** * Uncompress using a gzip uncompress algorithm from the `pulledFile` to the `outDir`. * Unlike `org.apache.druid.java.util.common.CompressionUtils.gunzip`, this function takes an output *DIRECTORY* and tries to guess the file name. * It is recommended that the caller use `org.apache.druid.java.util.common.CompressionUtils.gunzip` and specify the output file themselves to ensure names are as expected * * @param pulledFile The source file * @param outDir The destination directory to put the resulting file * * @throws IOException on propagated IO exception, IAE if it cannot determine the proper new name for `pulledFile` */ @Deprecated // See description for alternative public static void gunzip(File pulledFile, File outDir) { final File outFile = new File(outDir, org.apache.druid.java.util.common.CompressionUtils.getGzBaseName(pulledFile.getName())); org.apache.druid.java.util.common.CompressionUtils.gunzip(pulledFile, outFile); if (!pulledFile.delete()) { log.error("Could not delete tmpFile[%s].", pulledFile); } }
final FileUtils.FileCopyResult result = CompressionUtils.gunzip( Files.asByteSource(sourceFile), outFile,
final File outFile = new File(outDir, fname); final FileUtils.FileCopyResult result = CompressionUtils.gunzip(byteSource, outFile, S3Utils.S3RETRY); log.info("Loaded %d bytes from [%s] to [%s]", result.size(), s3Coords.toString(), outFile.getAbsolutePath()); return result;