public String getFileContentInsideZip(ZipInputStream zipInputStream, String file) throws IOException { ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { if (new File(zipEntry.getName()).getName().equals(file)) { return IOUtils.toString(zipInputStream, UTF_8); } zipEntry = zipInputStream.getNextEntry(); } return null; }
private void getNextEntry() throws IOException { ze = zis.getNextEntry(); if (ze == null) { zis.close(); } }
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())); } }
/** * @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... */ }
jarEntry = jarStream.getNextEntry(); String entryName = jarEntry.getName(); if (!jarEntry.isDirectory() && entryName.endsWith(".class")) { jarEntry = jarStream.getNextEntry();
ZipEntry nextEntry = zip.getNextEntry(); if ( nextEntry == null ) zip.close(); return null; String name = nextEntry.getName(); if ( name.endsWith( ".class" ) ) zip.close(); throw e;
return bs; case ZIP: { ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bs)); ZipEntry ze = zis.getNextEntry(); // Get the *FIRST* entry if( ze != null && !ze.isDirectory() ) { is = zis; break; zis.close(); return bs; // Don't crash, ignore file if cannot unzip
@Override public Chunk read() throws IOException { ZipEntry entry = zipIn.getNextEntry(); if (entry == null) { return null; } int read; ByteArrayOutputStream contentByteArray = new ByteArrayOutputStream(); while (-1 != (read = zipIn.read())) { contentByteArray.write(read); } return new Chunk(StringUtil.fromHex(entry.getName()), contentByteArray.toByteArray(), contentByteArray.size(), null); }
ZipEntry entry = inputStream.getNextEntry(); while (entry != null) { if (entry.getName().contains("__MACOSX")) { inputStream.closeEntry(); } else if (entry.getName().contains(".json")) { composition = LottieCompositionFactory.fromJsonInputStreamSync(inputStream, cacheKey, false).getValue(); } else if (entry.getName().contains(".png")) { String[] splitName = entry.getName().split("/"); String name = splitName[splitName.length - 1]; entry = inputStream.getNextEntry();
} 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();
boolean isZipped = new ZipInputStream(yourInputStream).getNextEntry() != null;
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; }
MyIterator() { try { zis = new ZipInputStream(new FileInputStream(file)); ze = zis.getNextEntry(); } catch (IOException e) { throw new RuntimeException(e); } }
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() ] );
public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) { try { ZipEntry entry = zipInputStream.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { String entryName = entry.getName(); byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName); ResourceEntity resource = resourceEntityManager.create(); resource.setName(entryName); resource.setBytes(bytes); deployment.addResource(resource); } entry = zipInputStream.getNextEntry(); } } catch (Exception e) { throw new ActivitiException("problem reading zip input stream", e); } return this; }
in = newCloseShieldZipInputStream(is, charset); ZipEntry entry; while ((entry = in.getNextEntry()) != null) { try { action.process(in, entry); throw new ZipException("Failed to process zip entry '" + entry.getName() + " with action " + action, ze); in.close();
public InputStream getInputStream() throws IOException { ZipInputStream zis = Scans.makeZipInputStream(jarPath); ZipEntry ens = null; while (null != (ens = zis.getNextEntry())) { if (ens.getName().equals(entryName)) return zis; } throw Lang.impossible(); }
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(); }