/** * 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); }
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); }
/** * 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 * @param fsync True if the output file should be fsynced to disk * * @return The number of bytes (uncompressed) read from the input directory. * * @throws IOException */ public static long zip(File directory, File outputZipFile, boolean fsync) throws IOException { if (!isZip(outputZipFile.getName())) { log.warn("No .zip suffix[%s], putting files from [%s] into it anyway.", outputZipFile, directory); } try (final FileOutputStream out = new FileOutputStream(outputZipFile)) { long bytes = zip(directory, out); // For explanation of why fsyncing here is a good practice: // https://github.com/druid-io/druid/pull/5187#pullrequestreview-85188984 if (fsync) { out.getChannel().force(true); } return bytes; } }
final long indexSize = CompressionUtils.zip(indexFilesDir, zipOutFile);