use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project MSEC by Tencent.
the class GzipUtil method zip.
public static void zip(String srcFile, String destFile) throws Exception {
GzipCompressorOutputStream out = new GzipCompressorOutputStream(new FileOutputStream(destFile));
FileInputStream in = new FileInputStream(srcFile);
byte[] buf = new byte[10240];
while (true) {
int len = in.read(buf);
if (len <= 0) {
break;
}
out.write(buf, 0, len);
}
out.flush();
out.close();
in.close();
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project MSEC by Tencent.
the class GzipUtil method zip.
public static void zip(String srcFile, String destFile) throws Exception {
GzipCompressorOutputStream out = new GzipCompressorOutputStream(new FileOutputStream(destFile));
FileInputStream in = new FileInputStream(srcFile);
byte[] buf = new byte[10240];
while (true) {
int len = in.read(buf);
if (len <= 0) {
break;
}
out.write(buf, 0, len);
}
out.flush();
out.close();
in.close();
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project neo4j by neo4j.
the class Dumper method openArchiveOut.
private static ArchiveOutputStream openArchiveOut(Path archive) throws IOException {
// StandardOpenOption.CREATE_NEW is important here because it atomically asserts that the file doesn't
// exist as it is opened, avoiding a TOCTOU race condition which results in a security vulnerability. I
// can't see a way to write a test to verify that we are using this option rather than just implementing
// the check ourselves non-atomically.
TarArchiveOutputStream tarball = new TarArchiveOutputStream(new GzipCompressorOutputStream(Files.newOutputStream(archive, StandardOpenOption.CREATE_NEW)));
tarball.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
tarball.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
return tarball;
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project docker-client by spotify.
the class CompressedDirectory method create.
/**
* This method creates a gzip tarball of the specified directory. File permissions will be
* retained. The file will be created in a temporary directory using the {@link
* Files#createTempFile(String, String, java.nio.file.attribute.FileAttribute[])} method. The
* returned object is auto-closeable, and upon closing it, the archive file will be deleted.
*
* @param directory the directory to compress
* @return a Path object representing the compressed directory
* @throws IOException if the compressed directory could not be created.
*/
public static CompressedDirectory create(final Path directory) throws IOException {
final Path file = Files.createTempFile("docker-client-", ".tar.gz");
final Path dockerIgnorePath = directory.resolve(".dockerignore");
final ImmutableList<DockerIgnorePathMatcher> ignoreMatchers = parseDockerIgnore(dockerIgnorePath);
try (final OutputStream fileOut = Files.newOutputStream(file);
final GzipCompressorOutputStream gzipOut = new GzipCompressorOutputStream(fileOut);
final TarArchiveOutputStream tarOut = new TarArchiveOutputStream(gzipOut)) {
tarOut.setLongFileMode(LONGFILE_POSIX);
tarOut.setBigNumberMode(BIGNUMBER_POSIX);
Files.walkFileTree(directory, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new Visitor(directory, ignoreMatchers, tarOut));
} catch (Throwable t) {
// If an error occurs, delete temporary file before rethrowing exclude.
try {
Files.delete(file);
} catch (IOException e) {
// So we don't lose track of the reason the file was deleted... might be important
t.addSuppressed(e);
}
throw t;
}
return new CompressedDirectory(file);
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project RecordManager2 by moravianlibrary.
the class TarGzUtils method compress.
public static File compress(String sourcePath, String targetPath) throws IOException {
FileOutputStream fOut = null;
BufferedOutputStream bOut = null;
GzipCompressorOutputStream gzOut = null;
TarArchiveOutputStream tOut = null;
File targetFile = new File(targetPath);
try {
fOut = new FileOutputStream(targetFile);
bOut = new BufferedOutputStream(fOut);
gzOut = new GzipCompressorOutputStream(bOut);
tOut = new TarArchiveOutputStream(gzOut);
tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
addFileToTarGz(tOut, sourcePath, "");
} finally {
if (tOut != null) {
tOut.finish();
tOut.close();
}
if (gzOut != null)
gzOut.close();
if (bOut != null)
bOut.close();
if (fOut != null)
fOut.close();
}
return targetFile;
}
Aggregations