@Override public InputStream getInputStream() throws IOException { return in.getInputStream(current); } }
@Override public InputStream getInputStream(ZipArchiveEntry entry) throws IOException { InputStream is = zipFile.getInputStream(entry); return new CipherInputStream(is, ci); }
@Override public InputStream getInputStream(ZipArchiveEntry entry) throws IOException { if (zipArchive == null) throw new IllegalStateException("Zip File is closed"); return zipArchive.getInputStream(entry); }
@Override public void writeEntryDataTo(ArchiveEntry entry, OutputStream out) throws IOException { try (InputStream in = archive.getInputStream((ZipArchiveEntry) entry)) { IOUtils.copy(in, out); } } }, targetDirectory);
/** * Returns an input stream for reading the contents of the specified * zip file entry. * * <p> Closing this ZIP file will, in turn, close all input * streams that have been returned by invocations of this method. * * @param entry the zip file entry * @return the input stream for reading the contents of the specified * zip file entry. * @throws IOException if an I/O error has occurred * @throws IllegalStateException if the zip file has been closed */ @Override @SuppressWarnings("resource") public ZipArchiveThresholdInputStream getInputStream(ZipArchiveEntry entry) throws IOException { ZipArchiveThresholdInputStream zatis = new ZipArchiveThresholdInputStream(super.getInputStream(entry)); zatis.setEntry(entry); return zatis; }
/** * <p> * Convenience method to return the entry's content as a String if isUnixSymlink() * returns true for it, otherwise returns null. * </p> * * <p>This method assumes the symbolic link's file name uses the * same encoding that as been specified for this ZipFile.</p> * * @param entry ZipArchiveEntry object that represents the symbolic link * @return entry's content as a String * @throws IOException problem with content's input stream * @since 1.5 */ public String getUnixSymlink(final ZipArchiveEntry entry) throws IOException { if (entry != null && entry.isUnixSymlink()) { try (InputStream in = getInputStream(entry)) { return zipEncoding.decode(IOUtils.toByteArray(in)); } } return null; }
InputStream in = null; try { byte[] bytes = getBytesFromInputStream( zf.getInputStream(entry) );
@Nonnull @Override public InputStream getContents() throws IOException { return zipFile.getInputStream( zipEntry ); }
public static IWORKDocumentType detectType(ZipArchiveEntry entry, ZipFile zip) { try { if (entry == null) { return null; } try (InputStream stream = zip.getInputStream(entry)) { return detectType(stream); } } catch (IOException e) { return null; } }
@Nonnull @Override public InputStream getContents() throws IOException { final InputStream inputStream = zipFile.getInputStream( entry ); return new ClosingInputStream( streamTransformer.transform( this, inputStream ), inputStream ); }
/** * OpenDocument files, along with EPub files and ASiC ones, have a * mimetype entry in the root of their Zip file. This entry contains * the mimetype of the overall file, stored as a single string. */ private static MediaType detectOpenDocument(ZipFile zip) { try { ZipArchiveEntry mimetype = zip.getEntry("mimetype"); if (mimetype != null) { try (InputStream stream = zip.getInputStream(mimetype)) { return MediaType.parse(IOUtils.toString(stream, UTF_8)); } } else { return null; } } catch (IOException e) { return null; } }
protected Map<String, String> readZipArchive(InputStream inputStream) throws IOException { Map<String, String> data = new HashMap<String, String>(); Path tempFile = writeTemporaryArchiveFile(inputStream, "zip"); ZipFile zip = new ZipFile(tempFile.toFile()); Enumeration<ZipArchiveEntry> entries = zip.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(zip.getInputStream(entry), bos); data.put(entry.getName(), DigestUtils.md5Hex(bos.toByteArray())); } zip.close(); Files.delete(tempFile); return data; }
protected String readArchiveText(InputStream inputStream) throws IOException { Path tempFile = writeTemporaryArchiveFile(inputStream, "zip"); ZipFile zip = new ZipFile(tempFile.toFile()); zip.getEntry(UnpackerResource.TEXT_FILENAME); ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(zip.getInputStream(zip.getEntry(UnpackerResource.TEXT_FILENAME)), bos); zip.close(); Files.delete(tempFile); return bos.toString(UTF_8.name()); }
in = zipFile.getInputStream( ze );
if ( isSelected( fileInfo.getName(), fileInfo ) ) in = zf.getInputStream( ze );
public static IWORKDocumentType detectType(ZipArchiveEntry entry, ZipFile zip) { try { if (entry == null) { return null; } try (InputStream stream = zip.getInputStream(entry)) { return detectType(stream); } } catch (IOException e) { return null; } }
@Override @Nullable public ArchiveEntry getNextEntry() throws IOException { if (!this.entries.hasMoreElements()) { this.stream = null; return null; } ZipArchiveEntry zae = this.entries.nextElement(); this.stream = this.zipFile.getInputStream(zae); return zae; }
/** * Retrieves the Manifest entry as a String * @param zipFile the zip file from which to extract the manifest * @return a String representing the manifest contents * @throws IOException */ public static String extractManifest(ZipFile zipFile) throws IOException{ ZipArchiveEntry entry = zipFile.getEntry(IW3CXMLConfiguration.MANIFEST_FILE); return IOUtils.toString(zipFile.getInputStream(entry), "UTF-8"); }
@Override public byte[] next() { try { ZipArchiveEntry entry = this.iter.nextElement(); try (InputStream in = this.zf.getInputStream(entry);) { byte[] bytes = IOUtils.toByteArray(in); return bytes; } } catch (IOException e) { throw new RuntimeException(e); } }
@Test public void testHandleFileEntry() throws IOException, RepositoryException { //GIVEN when(zipArchiveEntry.getName()).thenReturn("folderName/fileName.jpg"); inputStream = new ByteArrayInputStream(new byte[10]); when(zipFile.getInputStream(zipArchiveEntry)).thenReturn(inputStream); //WHEN importZipCommand.handleFileEntry(zipFile, zipArchiveEntry); //then should not thrown PathNotFoundException //THEN assertThat(mockContext.getJCRSession("assets").getRootNode(), hasNode("folderName", NodeTypes.Folder.NAME)); } }