use of org.apache.commons.compress.archivers.ArchiveInputStream in project gerrit by GerritCodeReview.
the class UploadArchiveIT method verifyUploadArchive.
private void verifyUploadArchive(String format) throws Exception {
Path outputPath = sitePaths.data_dir.resolve(ARCHIVE);
execute(cmd(format, commit.commit), sitePaths.data_dir.toFile(), ImmutableMap.of("GIT_SSH_COMMAND", GIT_SSH_COMMAND + identityPath), outputPath);
try (InputStream fi = Files.newInputStream(outputPath);
InputStream bi = new BufferedInputStream(fi);
ArchiveInputStream archive = archiveStreamForFormat(bi, format)) {
assertEntries(archive);
}
}
use of org.apache.commons.compress.archivers.ArchiveInputStream in project stream-applications by spring-cloud.
the class ModelExtractor method getModel.
public byte[] getModel(Resource modelResource) {
Validate.notNull(modelResource, "Not null model resource is required!");
try (InputStream is = modelResource.getInputStream();
InputStream bi = new BufferedInputStream(is)) {
String[] archiveCompressor = detectArchiveAndCompressor(modelResource.getFilename());
String archive = archiveCompressor[0];
String compressor = archiveCompressor[1];
String fragment = modelResource.getURI().getFragment();
if (StringUtils.isNotBlank(compressor)) {
try (CompressorInputStream cis = new CompressorStreamFactory().createCompressorInputStream(compressor, bi)) {
if (StringUtils.isNotBlank(archive)) {
try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(archive, cis)) {
// Compressor fromMemory Archive
return findInArchiveStream(fragment, ais);
}
} else {
// Compressor only
return IOUtils.toByteArray(cis);
}
}
} else if (StringUtils.isNotBlank(archive)) {
// Archive only
try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(archive, bi)) {
return findInArchiveStream(fragment, ais);
}
} else {
// No compressor nor Archive
return IOUtils.toByteArray(bi);
}
} catch (Exception e) {
throw new IllegalStateException("Failed to extract a model from: " + modelResource.getDescription(), e);
}
}
use of org.apache.commons.compress.archivers.ArchiveInputStream in project document-management-system by openkm.
the class ZipTest method testApache.
public void testApache() throws IOException, ArchiveException {
log.debug("testApache()");
File zip = File.createTempFile("apache_", ".zip");
// Create zip
FileOutputStream fos = new FileOutputStream(zip);
ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
aos.closeArchiveEntry();
aos.close();
// Read zip
FileInputStream fis = new FileInputStream(zip);
ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
assertEquals(zae.getName(), "coñeta");
ais.close();
}
use of org.apache.commons.compress.archivers.ArchiveInputStream in project cloud-pipeline by epam.
the class ScanService method fetchLayer.
private void fetchLayer(ScanRequest.Layer layerToScan, File layerFolder) throws IOException {
GZIPInputStream gzipInputStream = new GZIPInputStream(new BufferedInputStream(dockerRegistryService.getDockerLayerBlob(layerToScan)));
LOGGER.debug("Unpack layer: " + layerToScan.getName() + " into: " + layerFolder.getAbsolutePath());
try (ArchiveInputStream tarStream = new TarArchiveInputStream(gzipInputStream)) {
ArchiveEntry entry;
while ((entry = tarStream.getNextEntry()) != null) {
String entryName = entry.getName();
final File entryFile = new File(layerFolder, entryName);
if (entry.isDirectory()) {
Files.createDirectory(entryFile.toPath());
} else {
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(entryFile))) {
IOUtils.copy(tarStream, out);
}
}
}
LOGGER.debug("Successfully unpack layer: " + layerToScan.getName());
}
}
use of org.apache.commons.compress.archivers.ArchiveInputStream in project uPortal by Jasig.
the class JaxbPortalDataHandlerService method importDataArchive.
private void importDataArchive(Resource archive, InputStream resourceStream, BatchImportOptions options) {
BufferedInputStream bufferedResourceStream = null;
try {
// Make sure the stream is buffered
if (resourceStream instanceof BufferedInputStream) {
bufferedResourceStream = (BufferedInputStream) resourceStream;
} else {
bufferedResourceStream = new BufferedInputStream(resourceStream);
}
// Buffer up to 100MB, bad things will happen if we bust this buffer.
// TODO see if there is a buffered stream that will write to a file once the buffer
// fills up
bufferedResourceStream.mark(100 * 1024 * 1024);
final MediaType type = getMediaType(bufferedResourceStream, archive.getFilename());
if (MT_JAVA_ARCHIVE.equals(type)) {
final ArchiveInputStream archiveStream = new JarArchiveInputStream(bufferedResourceStream);
importDataArchive(archive, archiveStream, options);
} else if (MediaType.APPLICATION_ZIP.equals(type)) {
final ArchiveInputStream archiveStream = new ZipArchiveInputStream(bufferedResourceStream);
importDataArchive(archive, archiveStream, options);
} else if (MT_CPIO.equals(type)) {
final ArchiveInputStream archiveStream = new CpioArchiveInputStream(bufferedResourceStream);
importDataArchive(archive, archiveStream, options);
} else if (MT_AR.equals(type)) {
final ArchiveInputStream archiveStream = new ArArchiveInputStream(bufferedResourceStream);
importDataArchive(archive, archiveStream, options);
} else if (MT_TAR.equals(type)) {
final ArchiveInputStream archiveStream = new TarArchiveInputStream(bufferedResourceStream);
importDataArchive(archive, archiveStream, options);
} else if (MT_BZIP2.equals(type)) {
final CompressorInputStream compressedStream = new BZip2CompressorInputStream(bufferedResourceStream);
importDataArchive(archive, compressedStream, options);
} else if (MT_GZIP.equals(type)) {
final CompressorInputStream compressedStream = new GzipCompressorInputStream(bufferedResourceStream);
importDataArchive(archive, compressedStream, options);
} else if (MT_PACK200.equals(type)) {
final CompressorInputStream compressedStream = new Pack200CompressorInputStream(bufferedResourceStream);
importDataArchive(archive, compressedStream, options);
} else if (MT_XZ.equals(type)) {
final CompressorInputStream compressedStream = new XZCompressorInputStream(bufferedResourceStream);
importDataArchive(archive, compressedStream, options);
} else {
throw new RuntimeException("Unrecognized archive media type: " + type);
}
} catch (IOException e) {
throw new RuntimeException("Could not load InputStream for resource: " + archive, e);
} finally {
IOUtils.closeQuietly(bufferedResourceStream);
}
}
Aggregations