use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project carbondata by apache.
the class GzipCompressor method compressData.
/**
* This method takes the Byte Array data and Compresses in gzip format
*
* @param data Data Byte Array passed for compression
* @return Compressed Byte Array
*/
private byte[] compressData(byte[] data, int offset, int length) {
int initialSize = (length / 2) == 0 ? length : length / 2;
ByteArrayOutputStream output = new ByteArrayOutputStream(initialSize);
try (GzipCompressorOutputStream stream = new GzipCompressorOutputStream(output)) {
/*
* Below api will write bytes from specified byte array to the gzipCompressorOutputStream
* The output stream will compress the given byte array.
*/
stream.write(data, offset, length);
} catch (IOException e) {
throw new RuntimeException("Error during Compression writing step ", e);
}
return output.toByteArray();
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project nodejs-plugin by jenkinsci.
the class NodeJSInstaller method buildCache.
private void buildCache(FilePath expected, File cache) throws IOException, InterruptedException {
// update the local cache on master
// download to a temporary file and rename it in to handle concurrency and failure correctly,
Path tmp = new File(cache.getPath() + ".tmp").toPath();
try {
Path tmpParent = tmp.getParent();
if (tmpParent != null) {
Files.createDirectories(tmpParent);
}
try (OutputStream out = new GzipCompressorOutputStream(Files.newOutputStream(tmp))) {
// workaround to not store current folder as root folder in the archive
// this prevent issue when tool name is renamed
expected.tar(out, "**");
}
Files.move(tmp, cache.toPath(), StandardCopyOption.REPLACE_EXISTING);
} finally {
Files.deleteIfExists(tmp);
}
}
use of org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream in project nodejs-plugin by jenkinsci.
the class NodeJSInstallerTest method fillArchive.
private void fillArchive(File file, String fileEntry, byte[] content) throws IOException {
try (TarArchiveOutputStream zf = new TarArchiveOutputStream(new GzipCompressorOutputStream(new FileOutputStream(file)))) {
TarArchiveEntry ze = new TarArchiveEntry(fileEntry);
ze.setSize(content.length);
zf.putArchiveEntry(ze);
IOUtils.write(content, zf);
zf.closeArchiveEntry();
}
}
Aggregations