@Signature public void __construct(InputStream inputStream, String encoding) { __wrappedObject = new ZipArchiveInputStream(inputStream, encoding != null && encoding.isEmpty() ? null : encoding); }
@Override protected PArchiveInput createInput(Environment env) { return new PZipArchiveInput(env, new ZipArchiveInputStream(Stream.getInputStream(env, getSource()))); }
/** * Opens the specified stream as a secure zip * * @param stream * The stream to open. * @return The zip stream freshly open. */ @SuppressWarnings("resource") public static ZipArchiveThresholdInputStream openZipStream(InputStream stream) throws IOException { // Peek at the first few bytes to sanity check InputStream checkedStream = FileMagic.prepareToCheckMagic(stream); verifyZipHeader(checkedStream); // Open as a proper zip stream return new ZipArchiveThresholdInputStream(new ZipArchiveInputStream(checkedStream)); }
/** * open an Archive InputStream * @param in the InputStream to the archive * @return the ArchiveInputStream to read from * @throws IOException if an I/O error occurs * @throws java.lang.IllegalStateException if no archive method has been choose */ private ArchiveInputStream openArchiveStream(InputStream in) throws IOException, IllegalStateException { switch (mCurrentTask.archiver) { case tar: return new TarArchiveInputStream(new BufferedInputStream(openCompressedStream(in))); case zip: return new ZipArchiveInputStream(new BufferedInputStream(openCompressedStream(in))); default: throw new IllegalStateException("trying to open an archive, but no archive algorithm selected."); } }
/** * Extracts the contents of an archive into the specified directory. * * @param archive an archive file such as a WAR or EAR * @param destination a directory to extract the contents to * @param filter determines which files get extracted * @throws ExtractionException thrown if the archive is not found */ public static void extractFilesUsingFilter(File archive, File destination, FilenameFilter filter) throws ExtractionException { if (archive == null || destination == null) { return; } try (FileInputStream fis = new FileInputStream(archive)) { extractArchive(new ZipArchiveInputStream(new BufferedInputStream(fis)), destination, filter); } catch (FileNotFoundException ex) { final String msg = String.format("Error extracting file `%s` with filter: %s", archive.getAbsolutePath(), ex.getMessage()); LOGGER.debug(msg, ex); throw new ExtractionException(msg); } catch (IOException | ArchiveExtractionException ex) { LOGGER.warn("Exception extracting archive '{}'.", archive.getAbsolutePath()); LOGGER.debug("", ex); throw new ExtractionException("Unable to extract from archive", ex); } }
@Override public void process(final InputStream in) throws IOException { int fragmentCount = 0; try (final ZipArchiveInputStream zipIn = new ZipArchiveInputStream(new BufferedInputStream(in))) { ArchiveEntry zipEntry; while ((zipEntry = zipIn.getNextEntry()) != null) {
in = new BufferedInputStream(fis); ensureReadableJar(archiveExt, in); zin = new ZipArchiveInputStream(in); extractArchive(zin, destination, engine); } else if ("tar".equals(archiveExt)) {
return new ZipArchiveInputStream(in, actualEncoding); return new ZipArchiveInputStream(in);
public ZipPartStore(InputStream is) throws Docx4JException { initMaxBytes(); partByteArrays = new HashMap<String, ByteArray>(); try { ZipArchiveInputStream zis = new ZipArchiveInputStream(is); ArchiveEntry entry = null; while ((entry = zis.getNextEntry()) != null) { // How to read the data descriptor for length? ie before reading? byte[] bytes = getBytesFromInputStream( zis ); //log.debug("Extracting " + entry.getName()); policePartSize(null, bytes.length, entry.getName()); partByteArrays.put(entry.getName(), new ByteArray(bytes) ); } zis.close(); } catch (PartTooLargeException e) { throw e; } catch (Exception e) { throw new Docx4JException("Error processing zip file (is it a zip file?)", e); } }
@Test public void test1() throws IOException { ZipArchiveInputStream zis = new ZipArchiveInputStream(BadZipEntryFlagTest.class.getResourceAsStream("/bad.zip")); for (ZipArchiveEntry e = zis.getNextZipEntry(); e != null; e = zis.getNextZipEntry()) { e.getGeneralPurposeBit().useEncryption(false); if (!e.isDirectory()) { zis.read(); System.out.println(e.getName()); } } }
Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, CipherAlgorithm.aes128, ChainingMode.cbc, ivBytes, Cipher.ENCRYPT_MODE, PADDING); ZipArchiveInputStream zis = new ZipArchiveInputStream(is); FileOutputStream fos = new FileOutputStream(tmpFile); ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos);
private static MediaType tryStreamingDetection(TikaInputStream stream) { Set<String> entryNames = new HashSet<>(); try (InputStream is = new FileInputStream(stream.getFile())) { ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(is); ZipArchiveEntry zae = zipArchiveInputStream.getNextZipEntry(); while (zae != null) {
/** * @param stream the stream to read from, should be buffered * @param encoding the encoding of the entry names */ @Override public ArchiveInputStream getArchiveStream(InputStream stream, String encoding) throws IOException { return new ZipArchiveInputStream(stream, encoding, true); }
@Override protected ArchiveInputStream open(InputStream containerInputStream) { return new ZipArchiveInputStream(containerInputStream); } }
@Override protected ArchiveInputStream open(InputStream containerInputStream) { return new ZipArchiveInputStream(containerInputStream); } }
private static void repairCopy(File brokenZip, File fixedZip) { try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(fixedZip)) { try (InputStream is = new FileInputStream(brokenZip)) { ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(is); ZipArchiveEntry zae = zipArchiveInputStream.getNextZipEntry(); while (zae != null) {
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { ZipArchiveInputStream zip = new ZipArchiveInputStream(stream); ZipArchiveEntry entry = zip.getNextZipEntry();
@Override protected ArchiveInputStream compressedInputStream(InputStream compressedFile) { BufferedInputStream in = new BufferedInputStream(compressedFile); return new ZipArchiveInputStream(in); }
/** * Extract zip specified by url to target. * * @param sourceDistribution url of the archive * @param targetDirectory path of the target * @throws IOException */ private static void extractZipDistribution(URL sourceDistribution, File targetDirectory) throws IOException { extract(new ZipArchiveInputStream(sourceDistribution.openStream()), targetDirectory); }
public LineIterator getEntries() throws IOException { if(name.endsWith(".zip")){ ZipArchiveInputStream zipIn = new ZipArchiveInputStream(is); zipIn.getNextEntry(); return IOUtils.lineIterator(zipIn, "UTF-8"); } else { return IOUtils.lineIterator(is, "UTF-8"); } }