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; }
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]; images.put(name, BitmapFactory.decodeStream(inputStream)); } else { inputStream.closeEntry(); entry = inputStream.getNextEntry();
final ZipInputStream zipIn = new ZipInputStream(pipedIn); zipIn.getNextEntry(); FileUtils.copy(zipIn, destination); zipIn.closeEntry();
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(); }
zis = new ZipInputStream(new BufferedInputStream(is)); ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.getNextEntry()) != null) filename = ze.getName(); if (ze.isDirectory()) { File fmd = new File(path + filename); fmd.mkdirs(); continue; zis.closeEntry(); zis.close();
private static byte[] readMavenFileFromJarFile(URL jarFileLocation, String pomFileName) throws IOException { final ZipInputStream zipInputStream = new ZipInputStream( new BufferedInputStream(jarFileLocation.openStream(), 4096)); try { ZipEntry entry = zipInputStream.getNextEntry(); while (entry != null) { if (entry.getName().startsWith("META-INF/maven/") && entry.getName().endsWith("/" + pomFileName)) { return InputOutput.pumpToByteArray(zipInputStream); } zipInputStream.closeEntry(); entry = zipInputStream.getNextEntry(); } } finally { zipInputStream.close(); } return null; }
private static void unzipPythonLibrary(Path targetDir) throws IOException { FileSystem targetFs = targetDir.getFileSystem(); ClassLoader classLoader = PythonPlanBinder.class.getClassLoader(); try (ZipInputStream zis = new ZipInputStream(classLoader.getResourceAsStream("python-source.zip"))) { ZipEntry entry = zis.getNextEntry(); while (entry != null) { String fileName = entry.getName(); Path newFile = new Path(targetDir, fileName); if (entry.isDirectory()) { targetFs.mkdirs(newFile); } else { try { LOG.debug("Unzipping to {}.", newFile); FSDataOutputStream fsDataOutputStream = targetFs.create(newFile, FileSystem.WriteMode.NO_OVERWRITE); IOUtils.copyBytes(zis, fsDataOutputStream, false); } catch (Exception e) { zis.closeEntry(); throw new IOException("Failed to unzip flink python library.", e); } } zis.closeEntry(); entry = zis.getNextEntry(); } zis.closeEntry(); } }
try (ZipInputStream zipIn = new ZipInputStream(in)) { while (true) { ZipEntry entry = zipIn.getNextEntry(); if (entry == null) { break; String entryName = entry.getName(); if (!entryName.startsWith("/")) { entryName = "/" + entryName; ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(zipIn, out); zipIn.closeEntry(); return out.toByteArray(); zipIn.closeEntry();
public static void unzip(InputStream zip, String destFolder) { try { File folder = new File(destFolder); folder.mkdirs(); ZipInputStream zis = new ZipInputStream(zip); ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (!ze.isDirectory()) { String fileName = ze.getName(); File newFile = new File(destFolder + File.separator + fileName); newFile.getParentFile().mkdirs(); IO.save(newFile.getAbsolutePath(), IO.loadBytes(zis)); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException e) { throw U.rte(e); } }
ZipInputStream inZip = new ZipInputStream( new BufferedInputStream( new FileInputStream(filePath))); while((ze = inZip.getNextEntry()) != null) { if(ze.getName().equals(name)) { found = true; File oldFile = new File(file); if(oldFile.exists()) { if(!oldFile.delete()) { inZip.closeEntry();
public static String detectZipRoot(InputStream zip) { Set<String> roots = U.set(); try { ZipInputStream zis = new ZipInputStream(zip); ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (ze.isDirectory()) { String fileName = ze.getName(); String parentDir = fileName.split("/|\\\\")[0]; roots.add(parentDir); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException e) { throw U.rte(e); } return roots.size() == 1 ? U.single(roots) : null; }
ZipInputStream zipIn = new ZipInputStream(in); String originalDbName = null; boolean multiple = false; while (true) { ZipEntry entry = zipIn.getNextEntry(); if (entry == null) { break; String entryName = entry.getName(); zipIn.closeEntry(); String name = getDatabaseNameFromFileName(entryName); if (name != null) { zipIn.close(); if (multiple && !db.equals(originalDbName)) { throw new IOException("Multiple databases found, but not " + db);
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(fileZipPath)); ZipEntry zipEntry = zipInputStream.getNextEntry(); while (zipEntry != null) { String fileName = zipEntry.getName(); File outputFile = new File(destinationDirectory + File.separator + fileName); if (!outputFile.getCanonicalPath().startsWith(new File(destinationDirectory).getCanonicalPath())) { BallerinaSdkService.LOG.info("Arbitrary File Write attack attempted via an archive file. File name: " + outputFile.getName()); if (zipEntry.isDirectory()) { outputFile.mkdir(); zipEntry = zipInputStream.getNextEntry(); continue; new File(outputFile.getParent()).mkdirs(); zipEntry = zipInputStream.getNextEntry(); zipInputStream.closeEntry(); zipInputStream.close();
location += "/"; File f = new File(location); if(!f.isDirectory()) { f.mkdirs(); ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile), BUFFER_SIZE)); try { ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { String path = location + ze.getName(); File unzipFile = new File(path); if (ze.isDirectory()) { if(!unzipFile.isDirectory()) { unzipFile.mkdirs(); zin.closeEntry(); zin.close();
ZipInputStream zis = new ZipInputStream(fromIs); try { ZipEntry ze = zis.getNextEntry(); byte[] buffer = new byte[8 * 1024]; while (ze != null) { if (ze.isDirectory()) { new File(toFolder, ze.getName()).mkdir(); } else { double factor = 1; factor = (double) ze.getCompressedSize() / ze.getSize(); File newFile = new File(toFolder, ze.getName()); FileOutputStream fos = new FileOutputStream(newFile); try { ze = zis.getNextEntry(); zis.closeEntry(); } finally { zis.close();
try (ZipInputStream input = new ZipInputStream(new FileInputStream(sourceFile))) { while ((entry = input.getNextEntry()) != null) { if (entry.isDirectory()) { continue; final File file = new File(outputDir, entry.getName()); final File parent = file.getParentFile(); if (!parent.exists() && !parent.mkdirs()) { IOUtils.copy(input, output); } catch (final Exception e) { throw new RuntimeException("Error expanding entry '" + entry.getName() + "'", e); input.closeEntry(); } catch (final IOException e) { throw new KsqlException(
private Sprite getImageFromZip(File f, String name) throws IOException { ZipInputStream zis = null; try { zis = new ZipInputStream(new FileInputStream(f)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { final String fileName = ze.getName(); if (ze.isDirectory()) { } else if (fileName.equals(name)) { if (isSvg(name)) { return new SpriteSvg(FileUtils.readSvg(zis)); } else { return new SpriteImage(ImageIO.read(zis)); } } ze = zis.getNextEntry(); } } finally { if (zis != null) { zis.closeEntry(); zis.close(); } } return null; }
File f = new File(location); if(!f.isDirectory()) { f.mkdirs(); ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile)); try { ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { String path = location + ze.getName(); if (ze.isDirectory()) { File unzipFile = new File(path); if(!unzipFile.isDirectory()) { unzipFile.mkdirs(); fout.write(c); zin.closeEntry(); zin.close();
try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile))) { if (log.isLoggable(Level.FINE)) { log.fine("Unzipping emulator"); ZipEntry entry = zipIn.getNextEntry(); while (entry != null) { File filePath = new File(emulatorFolder, entry.getName()); String canonicalEmulatorFolderPath = emulatorFolder.getCanonicalPath(); String canonicalFilePath = filePath.getCanonicalPath(); if (!canonicalFilePath.startsWith(canonicalEmulatorFolderPath + File.separator)) { throw new IllegalStateException( "Entry is outside of the target dir: " + entry.getName()); if (!entry.isDirectory()) { extractFile(zipIn, filePath); } else { filePath.mkdir(); zipIn.closeEntry(); entry = zipIn.getNextEntry();
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { try { ZIPCompressedMessage result = new ZIPCompressedMessage(); byte[] byteArray = new byte[data.remaining()]; data.get(byteArray); ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(byteArray)); in.getNextEntry(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] tmp = new byte[9012]; int read; while (in.available() > 0 && ((read = in.read(tmp)) > 0)) { out.write(tmp, 0, read); } in.closeEntry(); out.flush(); in.close(); result.setMessage((Message)Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray()))); return (T)result; } catch (Exception e) { e.printStackTrace(); throw new IOException(e.toString()); } }