use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project alluxio by Alluxio.
the class TarUtils method getTarArchiveOutputStream.
private static TarArchiveOutputStream getTarArchiveOutputStream(String path) throws IOException {
// Generate tar.gz file
TarArchiveOutputStream taos = new TarArchiveOutputStream(new GzipCompressorOutputStream(new FileOutputStream(path)));
// TAR has an 8G file limit by default, this gets around that
taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
// TAR originally does not support long file names, enable the support for it
taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
taos.setAddPaxHeadersForNonAsciiNames(true);
return taos;
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project zeppelin by apache.
the class TarUtils method getTarArchiveOutputStream.
private static TarArchiveOutputStream getTarArchiveOutputStream(String name) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(name);
GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(fileOutputStream);
TarArchiveOutputStream taos = new TarArchiveOutputStream(gzipOutputStream);
// TAR has an 8 gig file limit by default, this gets around that
taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
// TAR originally didn't support long file names, so enable the support for it
taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
taos.setAddPaxHeadersForNonAsciiNames(true);
return taos;
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project twister2 by DSC-SPIDAL.
the class TarGzipPacker method createTarGzipPacker.
/**
* create TarGzipPacker object
*/
public static TarGzipPacker createTarGzipPacker(String targetDir, Config config) {
// this should be received from config
String archiveFilename = SchedulerContext.jobPackageFileName(config);
Path archiveFile = Paths.get(targetDir + "/" + archiveFilename);
try {
// construct output stream
OutputStream outStream = Files.newOutputStream(archiveFile);
GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(outStream);
TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream);
return new TarGzipPacker(archiveFile, tarOutputStream);
} catch (IOException ioe) {
LOG.log(Level.SEVERE, "Archive file can not be created: " + archiveFile, ioe);
return null;
}
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project karaf by apache.
the class ArchiveMojo method archive.
public // ArchiverException,
File archive(// ArchiverException,
File source, // ArchiverException,
File dest, // ArchiverException,
Artifact artifact) throws IOException {
String serverName = null;
if (targetFile != null) {
serverName = targetFile.getName();
} else {
serverName = artifact.getArtifactId() + "-" + artifact.getVersion();
}
dest = new File(dest, serverName + "." + artifact.getType());
String prefix = "";
if (usePathPrefix) {
prefix = pathPrefix.trim();
if (prefix.length() > 0 && !prefix.endsWith("/")) {
prefix += "/";
}
}
if ("tar.gz".equals(artifact.getType())) {
try (OutputStream fOut = Files.newOutputStream(dest.toPath());
OutputStream bOut = new BufferedOutputStream(fOut);
OutputStream gzOut = new GzipCompressorOutputStream(bOut);
TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut);
DirectoryStream<Path> children = Files.newDirectoryStream(source.toPath())) {
tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
tOut.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
for (Path child : children) {
addFileToTarGz(tOut, child, prefix);
}
}
} else if ("zip".equals(artifact.getType())) {
try (OutputStream fOut = Files.newOutputStream(dest.toPath());
OutputStream bOut = new BufferedOutputStream(fOut);
ZipArchiveOutputStream tOut = new ZipArchiveOutputStream(bOut);
DirectoryStream<Path> children = Files.newDirectoryStream(source.toPath())) {
for (Path child : children) {
addFileToZip(tOut, child, prefix);
}
}
} else {
throw new IllegalArgumentException("Unknown target type: " + artifact.getType());
}
return dest;
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project carbondata by apache.
the class GzipCompressor method compressData.
/**
* This method takes the ByteBuffer data and Compresses in gzip format
*
* @param input compression input
* @return Compressed Byte Array
*/
private byte[] compressData(ByteBuffer input) {
input.flip();
int initialSize = (input.limit() / 2) == 0 ? input.limit() : input.limit() / 2;
ByteArrayOutputStream output = new ByteArrayOutputStream(initialSize);
try (GzipCompressorOutputStream stream = new GzipCompressorOutputStream(output)) {
for (int i = 0; i < input.limit(); i++) {
stream.write(input.get(i));
}
} catch (IOException e) {
throw new RuntimeException("Error during Compression writing step ", e);
}
return output.toByteArray();
}
Aggregations