public static ZipInputStream makeZipInputStream(String jarPath) throws MalformedURLException, IOException { ZipInputStream zis = null; try { zis = new ZipInputStream(new FileInputStream(jarPath)); } catch (IOException e) { zis = new ZipInputStream(new URL(jarPath).openStream()); } return zis; }
boolean isZipped = new ZipInputStream(yourInputStream).getNextEntry() != null;
List<String> classNames = new ArrayList<String>(); ZipInputStream zip = new ZipInputStream(new FileInputStream("/path/to/jar/file.jar")); for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { if (!entry.isDirectory() && entry.getName().endsWith(".class")) { // This ZipEntry represents a class. Now, what class does it represent? String className = entry.getName().replace('/', '.'); // including ".class" classNames.add(className.substring(0, className.length() - ".class".length())); } }
extension = FileExtension.Zip; file = networkCache.writeTempCacheFile(connection.getInputStream(), extension); result = LottieCompositionFactory.fromZipStreamSync(new ZipInputStream(new FileInputStream(file)), url); break; case "application/json": extension = FileExtension.Json; file = networkCache.writeTempCacheFile(connection.getInputStream(), extension); result = LottieCompositionFactory.fromJsonInputStreamSync(new FileInputStream(new File(file.getAbsolutePath())), url); break;
/** * @param zip Compressed file. */ public UnzipFileIO(File zip) throws IOException { zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zip))); ZipEntry entry = zis.getNextEntry(); size = entry.getSize(); }
public static void decompress(InputStream input, File destDir) throws IOException { ZipInputStream zin = new ZipInputStream(input); ZipEntry entry = null; byte[] buffer = new byte[1024]; while ((entry = zin.getNextEntry()) != null) { File f = getZipOutputFile(destDir, entry); if (entry.isDirectory()) { f.mkdirs(); continue; } BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f)); int n = -1; while ((n = zin.read(buffer)) != -1) { out.write(buffer, 0, n); } out.flush(); out.close(); } }
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); ZipInputStream zip = new ZipInputStream(jar.openStream()); while(true) { ZipEntry e = zip.getNextEntry(); if (e == null) break; String name = e.getName(); if (name.startsWith("path/to/your/dir/")) { /* Do something with this entry. */ ... } } } else { /* Fail... */ }
} else if (fileName.endsWith(ZIP_SUFFIX)) { final ZipInputStream zipIn = new ZipInputStream(in, StandardCharsets.UTF_8); try { final ZipEntry nextEntry = zipIn.getNextEntry(); if (nextEntry == null) { zipIn.close(); zipIn.close();
public void handle(InputStream stream) throws IOException { ZipInputStream zipInputStream = new ZipInputStream(stream); LOG.info("[Agent Fetch Artifact] Downloading from '{}' to '{}'. Will read from Socket stream to compute MD5 and write to file", srcFile, destOnAgent.getAbsolutePath()); long before = System.currentTimeMillis(); new ZipUtil((entry, stream1) -> { LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Handling the entry: '{}'", srcFile, destOnAgent.getAbsolutePath(), entry.getName()); new ChecksumValidator(artifactMd5Checksums).validate(getSrcFilePath(entry), md5Hex(stream1), checksumValidationPublisher); }).unzip(zipInputStream, destOnAgent); LOG.info("[Agent Fetch Artifact] Downloading a directory from '{}' to '{}'. Took: {}ms", srcFile, destOnAgent.getAbsolutePath(), System.currentTimeMillis() - before); }
public InputStream open() throws IOException { final ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { final String fileName = ze.getName(); if (ze.isDirectory()) { } else if (fileName.trim().equalsIgnoreCase(entry.trim())) { return zis; } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); throw new IOException(); }
@Test public void shouldReturnNullIfTheFileByTheNameDoesNotExistInsideZip() throws IOException, URISyntaxException { String contents = zipUtil.getFileContentInsideZip(new ZipInputStream(new FileInputStream(new File(getClass().getResource("/dummy-plugins.zip").toURI()))), "does_not_exist.txt"); assertThat(contents, is(nullValue())); }
MyIterator() { try { zis = new ZipInputStream(new FileInputStream(file)); ze = zis.getNextEntry(); } catch (IOException e) { throw new RuntimeException(e); } }
public void unzip(File zip, File destDir) throws IOException { unzip(new ZipInputStream(new BufferedInputStream(new FileInputStream(zip))), destDir); }
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource(); List<String> list = new ArrayList<String>(); if( src != null ) { URL jar = src.getLocation(); ZipInputStream zip = new ZipInputStream( jar.openStream()); ZipEntry ze = null; while( ( ze = zip.getNextEntry() ) != null ) { String entryName = ze.getName(); if( entryName.startsWith("images") && entryName.endsWith(".png") ) { list.add( entryName ); } } } webimages = list.toArray( new String[ list.size() ] );
return bs; case ZIP: { ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bs)); ZipEntry ze = zis.getNextEntry(); // Get the *FIRST* entry break; zis.close(); return bs; // Don't crash, ignore file if cannot unzip
/** * Unzip a file to a directory. * * @param stream the zip input file * @param toDir the target directory. It is created if needed. * @param filter filter zip entries so that only a subset of directories/files can be * extracted to target directory. * @return the parameter {@code toDir} * @since 6.2 */ public static File unzip(InputStream stream, File toDir, Predicate<ZipEntry> filter) throws IOException { if (!toDir.exists()) { FileUtils.forceMkdir(toDir); } Path targetDirNormalizedPath = toDir.toPath().normalize(); try (ZipInputStream zipStream = new ZipInputStream(stream)) { ZipEntry entry; while ((entry = zipStream.getNextEntry()) != null) { if (filter.test(entry)) { unzipEntry(entry, zipStream, targetDirNormalizedPath); } } return toDir; } }
private InputStream getDataFromZip(InputStream is, String name) throws IOException { final ZipInputStream zis = new ZipInputStream(is); ZipEntry ze = zis.getNextEntry(); while (ze != null) { final String fileName = ze.getName(); if (ze.isDirectory()) { } else if (fileName.equals(name)) { return zis; } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); return null; }
@Test public void shouldReadContentFromFileInsideZip() throws IOException, URISyntaxException { String contents = zipUtil.getFileContentInsideZip(new ZipInputStream(new FileInputStream(new File(getClass().getResource("/dummy-plugins.zip").toURI()))), "version.txt"); assertThat(contents, is("13.3.0(17222-4c7fabcb9c9e9c)")); }
@Override byte[] readFile(File file) throws IOException { InputStream is = new FileInputStream(file); ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); BufferedInputStream buff = new BufferedInputStream(zis); ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[0xFFFF]; int len; while ((len = buff.read(buffer)) > 0) { os.write(buffer, 0, len); } os.flush(); Helper.close(buff); return os.toByteArray(); }
in = new GZIPInputStream(in); } else if ("ZIP".equals(compressionAlgorithm)) { ZipInputStream z = new ZipInputStream(in); while (true) { ZipEntry entry = z.getNextEntry(); if (entry == null) { return null; if (entryName.equals(entry.getName())) { break;