List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveInputStream TarArchiveInputStream
public TarArchiveInputStream(InputStream is, int blockSize)
From source file:com.arturmkrtchyan.kafka.util.TarUnpacker.java
protected TarArchiveInputStream createTarArchiveInputStream(final InputStream inputStream, final boolean isGzipped) throws IOException { return (isGzipped) ? new TarArchiveInputStream(new GZIPInputStream(inputStream), BUFFER_SIZE) : new TarArchiveInputStream(new BufferedInputStream(inputStream), BUFFER_SIZE); }
From source file:edu.wisc.doit.tcrypt.BouncyCastleFileDecrypter.java
@Override public void decrypt(InputStream inputStream, OutputStream outputStream) throws InvalidCipherTextException, IOException, DecoderException { final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(inputStream, FileEncrypter.ENCODING); final BufferedBlockCipher cipher = createCipher(tarInputStream); //Advance to the next entry in the tar file tarInputStream.getNextTarEntry();/*from www . j a v a 2 s . c om*/ //Create digest output stream used to generate digest while decrypting final DigestOutputStream digestOutputStream = new DigestOutputStream(this.createDigester()); //Do a streaming decryption of the file output final CipherOutputStream cipherOutputStream = new CipherOutputStream( new TeeOutputStream(outputStream, digestOutputStream), cipher); IOUtils.copy(tarInputStream, cipherOutputStream); cipherOutputStream.close(); //Capture the hash of the decrypted output final byte[] hashBytes = digestOutputStream.getDigest(); verifyOutputHash(tarInputStream, hashBytes); }
From source file:com.petpet.c3po.gatherer.FileExtractor.java
/** * Obtains an apache compress {@link ArchiveInputStream} to the given archive * file.//from w w w . j a v a 2 s . co m * * @param src * the archive file. * @return the stream. */ private static ArchiveInputStream getStream(String src) { FileInputStream fis = null; ArchiveInputStream is = null; try { fis = new FileInputStream(src); if (src.endsWith(".zip")) { is = new ZipArchiveInputStream(fis); } else { boolean zip = src.endsWith(".tgz") || src.endsWith(".gz"); InputStream imp = (zip) ? new GZIPInputStream(fis, BUFFER_SIZE) : new BufferedInputStream(fis, BUFFER_SIZE); is = new TarArchiveInputStream(imp, BUFFER_SIZE); } } catch (IOException e) { LOG.warn("An error occurred while obtaining the stream to the archive '{}'. Error: {}", src, e.getMessage()); } return is; }
From source file:com.ifs.megaprofiler.helper.FileExtractor.java
/** * Obtains an apache compress {@link ArchiveInputStream} to the given * archive file.// w w w .j ava 2 s . c o m * * @param src * the archive file. * @return the stream. */ private static ArchiveInputStream getStream(String src) { FileInputStream fis = null; ArchiveInputStream is = null; try { fis = new FileInputStream(src); if (src.endsWith(".zip")) { is = new ZipArchiveInputStream(fis); } else { boolean zip = src.endsWith(".tgz") || src.endsWith(".gz"); InputStream imp = (zip) ? new GZIPInputStream(fis, BUFFER_SIZE) : new BufferedInputStream(fis, BUFFER_SIZE); is = new TarArchiveInputStream(imp, BUFFER_SIZE); } } catch (IOException e) { // LOG.warn( // "An error occurred while obtaining the stream to the archive '{}'. Error: {}", // src, e.getMessage() ); } return is; }
From source file:edu.wisc.doit.tcrypt.BouncyCastleFileDecrypter.java
@Override public InputStream decrypt(InputStream inputStream) throws InvalidCipherTextException, IOException, DecoderException { final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(inputStream, FileEncrypter.ENCODING); final BufferedBlockCipher cipher = createCipher(tarInputStream); //Advance to the next entry in the tar file tarInputStream.getNextTarEntry();/*from ww w . j a v a 2s . co m*/ //Protect the underlying TAR stream from being closed by the cipher stream final CloseShieldInputStream is = new CloseShieldInputStream(tarInputStream); //Setup the decrypting cipher stream final CipherInputStream stream = new CipherInputStream(is, cipher); //Generate a digest of the decrypted data final GeneralDigest digest = this.createDigester(); final DigestInputStream digestInputStream = new DigestInputStream(stream, digest); return new DecryptingInputStream(digestInputStream, tarInputStream, digest); }
From source file:org.apache.ant.compress.util.TarStreamFactory.java
/** * @param stream the stream to read from, should be buffered * @param encoding the encoding of the entry names *//* w w w . j a va 2s . c om*/ public ArchiveInputStream getArchiveStream(InputStream stream, String encoding) throws IOException { return new TarArchiveInputStream(stream, encoding); }
From source file:org.apache.tika.parser.pkg.TikaArchiveStreamFactory.java
@Override public ArchiveInputStream createArchiveInputStream(final String archiverName, final InputStream in, final String actualEncoding) throws ArchiveException { if (archiverName == null) { throw new IllegalArgumentException("Archivername must not be null."); }//from ww w .j a v a2s.c o m if (in == null) { throw new IllegalArgumentException("InputStream must not be null."); } if (AR.equalsIgnoreCase(archiverName)) { return new ArArchiveInputStream(in); } if (ARJ.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new ArjArchiveInputStream(in, actualEncoding); } return new ArjArchiveInputStream(in); } if (ZIP.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new ZipArchiveInputStream(in, actualEncoding); } return new ZipArchiveInputStream(in); } if (TAR.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new TarArchiveInputStream(in, actualEncoding); } return new TarArchiveInputStream(in); } if (JAR.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new JarArchiveInputStream(in, actualEncoding); } return new JarArchiveInputStream(in); } if (CPIO.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new CpioArchiveInputStream(in, actualEncoding); } return new CpioArchiveInputStream(in); } if (DUMP.equalsIgnoreCase(archiverName)) { if (actualEncoding != null) { return new DumpArchiveInputStream(in, actualEncoding); } return new DumpArchiveInputStream(in); } if (SEVEN_Z.equalsIgnoreCase(archiverName)) { throw new StreamingNotSupportedException(SEVEN_Z); } final ArchiveStreamProvider archiveStreamProvider = getArchiveInputStreamProviders() .get(toKey(archiverName)); if (archiveStreamProvider != null) { return archiveStreamProvider.createArchiveInputStream(archiverName, in, actualEncoding); } throw new ArchiveException("Archiver: " + archiverName + " not found."); }
From source file:org.polymap.p4.data.importer.archive.ArchiveReader.java
protected void handleTar(File dir, String name, InputStream in) throws Exception { log.info(" TAR: " + name); try (TarArchiveInputStream tar = new TarArchiveInputStream(in, charset.get().name())) { ArchiveEntry entry = null;/*from www . ja v a2 s . c o m*/ File subdir = dir; while ((entry = tar.getNextEntry()) != null) { String entryName = FilenameUtils.getName(entry.getName()); if (entry.isDirectory()) { subdir = new File(subdir, entryName); subdir.mkdir(); } else { handle(subdir, entryName, null, tar); } } } }
From source file:org.polymap.p4.data.imports.archive.ArchiveReader.java
protected void handleTar(String name, InputStream in) throws Exception { log.info(" TAR: " + name); try (TarArchiveInputStream tar = new TarArchiveInputStream(in, charset.get().name())) { ArchiveEntry entry = null;// www . java 2 s. co m while ((entry = tar.getNextEntry()) != null) { if (entry.isDirectory()) { } else { handle(entry.getName(), null, tar); } } } }