use of org.apache.commons.compress.archivers.ArchiveEntry in project weave by continuuity.
the class KafkaTest method extractKafka.
private static File extractKafka() throws IOException, ArchiveException, CompressorException {
File kafkaExtract = TMP_FOLDER.newFolder();
InputStream kakfaResource = KafkaTest.class.getClassLoader().getResourceAsStream("kafka-0.7.2.tgz");
ArchiveInputStream archiveInput = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.GZIP, kakfaResource));
try {
ArchiveEntry entry = archiveInput.getNextEntry();
while (entry != null) {
File file = new File(kafkaExtract, entry.getName());
if (entry.isDirectory()) {
file.mkdirs();
} else {
ByteStreams.copy(archiveInput, Files.newOutputStreamSupplier(file));
}
entry = archiveInput.getNextEntry();
}
} finally {
archiveInput.close();
}
return kafkaExtract;
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project camel by apache.
the class TarAggregationStrategy method addFileToTar.
private void addFileToTar(File source, File file, String fileName) throws IOException, ArchiveException {
File tmpTar = File.createTempFile(source.getName(), null, parentDir);
tmpTar.delete();
if (!source.renameTo(tmpTar)) {
throw new IOException("Could not make temp file (" + source.getName() + ")");
}
FileInputStream fis = new FileInputStream(tmpTar);
TarArchiveInputStream tin = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, fis);
TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(source));
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
InputStream in = new FileInputStream(file);
// copy the existing entries
ArchiveEntry nextEntry;
while ((nextEntry = tin.getNextEntry()) != null) {
tos.putArchiveEntry(nextEntry);
IOUtils.copy(tin, tos);
tos.closeArchiveEntry();
}
// Add the new entry
TarArchiveEntry entry = new TarArchiveEntry(fileName == null ? file.getName() : fileName);
entry.setSize(file.length());
tos.putArchiveEntry(entry);
IOUtils.copy(in, tos);
tos.closeArchiveEntry();
IOHelper.close(fis, in, tin, tos);
LOG.trace("Deleting temporary file: {}", tmpTar);
FileUtil.deleteFile(tmpTar);
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project cuba by cuba-platform.
the class LogArchiver method writeArchivedLogTailToStream.
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
if (!logFile.exists()) {
throw new FileNotFoundException();
}
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
zipOutputStream.setEncoding(ZIP_ENCODING);
byte[] content = getTailBytes(logFile);
ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content);
zipOutputStream.putArchiveEntry(archiveEntry);
zipOutputStream.write(content);
zipOutputStream.closeArchiveEntry();
zipOutputStream.close();
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project cuba by cuba-platform.
the class LogArchiver method writeArchivedLogToStream.
public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException {
if (!logFile.exists()) {
throw new FileNotFoundException();
}
File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip");
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile);
zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
zipOutputStream.setEncoding(ZIP_ENCODING);
ArchiveEntry archiveEntry = newArchive(logFile);
zipOutputStream.putArchiveEntry(archiveEntry);
FileInputStream logFileInput = new FileInputStream(logFile);
IOUtils.copyLarge(logFileInput, zipOutputStream);
logFileInput.close();
zipOutputStream.closeArchiveEntry();
zipOutputStream.close();
FileInputStream tempFileInput = new FileInputStream(tempFile);
IOUtils.copyLarge(tempFileInput, outputStream);
tempFileInput.close();
FileUtils.deleteQuietly(tempFile);
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project nifi by apache.
the class TestMergeContent method testTar.
@Test
public void testTar() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec");
runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_TAR);
final Map<String, String> attributes = new HashMap<>();
attributes.put(CoreAttributes.MIME_TYPE.key(), "application/plain-text");
attributes.put(CoreAttributes.FILENAME.key(), "AShortFileName");
runner.enqueue("Hello".getBytes("UTF-8"), attributes);
attributes.put(CoreAttributes.FILENAME.key(), "ALongerrrFileName");
runner.enqueue(", ".getBytes("UTF-8"), attributes);
attributes.put(CoreAttributes.FILENAME.key(), "AReallyLongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggFileName");
runner.enqueue("World!".getBytes("UTF-8"), attributes);
runner.run();
runner.assertQueueEmpty();
runner.assertTransferCount(MergeContent.REL_MERGED, 1);
runner.assertTransferCount(MergeContent.REL_FAILURE, 0);
runner.assertTransferCount(MergeContent.REL_ORIGINAL, 3);
final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0);
try (final InputStream rawIn = new ByteArrayInputStream(runner.getContentAsByteArray(bundle));
final TarArchiveInputStream in = new TarArchiveInputStream(rawIn)) {
ArchiveEntry entry = in.getNextEntry();
Assert.assertNotNull(entry);
assertEquals("AShortFileName", entry.getName());
final byte[] part1 = IOUtils.toByteArray(in);
Assert.assertTrue(Arrays.equals("Hello".getBytes("UTF-8"), part1));
entry = in.getNextEntry();
assertEquals("ALongerrrFileName", entry.getName());
final byte[] part2 = IOUtils.toByteArray(in);
Assert.assertTrue(Arrays.equals(", ".getBytes("UTF-8"), part2));
entry = in.getNextEntry();
assertEquals("AReallyLongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggFileName", entry.getName());
final byte[] part3 = IOUtils.toByteArray(in);
Assert.assertTrue(Arrays.equals("World!".getBytes("UTF-8"), part3));
}
bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/tar");
}
Aggregations