/** * Zip the contents of directory into the file indicated by outputZipFile. Sub directories are skipped * * @param directory The directory whose contents should be added to the zip in the output stream. * @param outputZipFile The output file to write the zipped data to * * @return The number of bytes (uncompressed) read from the input directory. * * @throws IOException */ public static long zip(File directory, File outputZipFile) throws IOException { return zip(directory, outputZipFile, false); }
@Deprecated // Use org.apache.druid.java.util.common.CompressionUtils.zip public static long zip(File directory, File outputZipFile) throws IOException { return org.apache.druid.java.util.common.CompressionUtils.zip(directory, outputZipFile); }
@Deprecated // Use org.apache.druid.java.util.common.CompressionUtils.zip public static long zip(File directory, OutputStream out) throws IOException { return org.apache.druid.java.util.common.CompressionUtils.zip(directory, out); }
private long compressSegment(File dataSegmentFile, File dest) throws IOException { log.info("Compressing files from[%s] to [%s]", dataSegmentFile, dest); return CompressionUtils.zip(dataSegmentFile, dest, true); }
@Test public void testGoodZipStream() throws IOException { final File tmpDir = temporaryFolder.newFolder("testGoodZipStream"); final File zipFile = new File(tmpDir, "compressionUtilTest.zip"); CompressionUtils.zip(testDir, new FileOutputStream(zipFile)); final File newDir = new File(tmpDir, "newDir"); newDir.mkdir(); CompressionUtils.unzip(new FileInputStream(zipFile), newDir); final Path newPath = Paths.get(newDir.getAbsolutePath(), testFile.getName()); Assert.assertTrue(newPath.toFile().exists()); try (final FileInputStream inputStream = new FileInputStream(newPath.toFile())) { assertGoodDataStream(inputStream); } }
@Test public void testGoodZipCompressUncompress() throws IOException { final File tmpDir = temporaryFolder.newFolder("testGoodZipCompressUncompress"); final File zipFile = new File(tmpDir, "compressionUtilTest.zip"); try { CompressionUtils.zip(testDir, zipFile); final File newDir = new File(tmpDir, "newDir"); newDir.mkdir(); CompressionUtils.unzip(zipFile, newDir); final Path newPath = Paths.get(newDir.getAbsolutePath(), testFile.getName()); Assert.assertTrue(newPath.toFile().exists()); try (final FileInputStream inputStream = new FileInputStream(newPath.toFile())) { assertGoodDataStream(inputStream); } } finally { if (zipFile.exists()) { zipFile.delete(); } if (tmpDir.exists()) { tmpDir.delete(); } } }
final long size = CompressionUtils.zip(indexFilesDir, zipOutFile);
long indexSize = CompressionUtils.zip(indexFilesDir, compressedIndexFile); log.info("Wrote compressed file [%s] to [%s]", compressedIndexFile.getAbsolutePath(), key);
@Test public void simpleZipTest() throws IOException, SegmentLoadingException { File file = new File(tmpDir, "test1data"); File zipFile = temporaryFolder.newFile("ziptest.zip"); try (OutputStream outputStream = new FileOutputStream(file)) { outputStream.write(new byte[0]); outputStream.flush(); } CompressionUtils.zip(tmpDir, zipFile); file.delete(); Assert.assertFalse(file.exists()); Assert.assertTrue(zipFile.exists()); puller.getSegmentFiles(zipFile, tmpDir); Assert.assertTrue(file.exists()); }
@Test public void testZipName() throws IOException { final File tmpDir = temporaryFolder.newFolder("testZipName"); final File zipDir = new File(tmpDir, "zipDir"); zipDir.mkdir(); final File file = new File(tmpDir, "zipDir.zip"); final Path unzipPath = Paths.get(zipDir.getPath(), "test.dat"); file.delete(); Assert.assertFalse(file.exists()); Assert.assertFalse(unzipPath.toFile().exists()); CompressionUtils.zip(testDir, file); Assert.assertTrue(file.exists()); CompressionUtils.unzip(file, zipDir); Assert.assertTrue(unzipPath.toFile().exists()); try (final FileInputStream inputStream = new FileInputStream(unzipPath.toFile())) { assertGoodDataStream(inputStream); } }
@Test public void testGoodZipCompressUncompressWithLocalCopy() throws IOException { final File tmpDir = temporaryFolder.newFolder("testGoodZipCompressUncompressWithLocalCopy"); final File zipFile = new File(tmpDir, "testGoodZipCompressUncompressWithLocalCopy.zip"); CompressionUtils.zip(testDir, zipFile); final File newDir = new File(tmpDir, "newDir"); newDir.mkdir(); CompressionUtils.unzip( new ByteSource() { @Override public InputStream openStream() throws IOException { return new FileInputStream(zipFile); } }, newDir, true ); final Path newPath = Paths.get(newDir.getAbsolutePath(), testFile.getName()); Assert.assertTrue(newPath.toFile().exists()); try (final FileInputStream inputStream = new FileInputStream(newPath.toFile())) { assertGoodDataStream(inputStream); } }
try { try (FSDataOutputStream out = fs.create(tmpIndexFile)) { size = CompressionUtils.zip(inDir, out);
final long indexSize = CompressionUtils.zip(indexFilesDir, zipOutFile);
final long indexSize = CompressionUtils.zip(indexFilesDir, indexFile); final String storageDir = this.getStorageDir(segment, useUniquePath); final String indexPath = buildPath(storageDir + "/" + "index.zip");
final File outFile = zipOutFile = File.createTempFile("druid", "index.zip"); final long indexSize = CompressionUtils.zip(indexFilesDir, zipOutFile);
/** * Zip the contents of directory into the file indicated by outputZipFile. Sub directories are skipped * * @param directory The directory whose contents should be added to the zip in the output stream. * @param outputZipFile The output file to write the zipped data to * * @return The number of bytes (uncompressed) read from the input directory. * * @throws IOException */ public static long zip(File directory, File outputZipFile) throws IOException { return zip(directory, outputZipFile, false); }
@Deprecated // Use org.apache.druid.java.util.common.CompressionUtils.zip public static long zip(File directory, File outputZipFile) throws IOException { return org.apache.druid.java.util.common.CompressionUtils.zip(directory, outputZipFile); }
@Deprecated // Use org.apache.druid.java.util.common.CompressionUtils.zip public static long zip(File directory, OutputStream out) throws IOException { return org.apache.druid.java.util.common.CompressionUtils.zip(directory, out); }
private long compressSegment(File dataSegmentFile, File dest) throws IOException { log.info("Compressing files from[%s] to [%s]", dataSegmentFile, dest); return CompressionUtils.zip(dataSegmentFile, dest, true); }