java.util.zip.ZipInputStream.closeEntry()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(540)

本文整理了Java中java.util.zip.ZipInputStream.closeEntry()方法的一些代码示例,展示了ZipInputStream.closeEntry()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipInputStream.closeEntry()方法的具体详情如下:
包路径:java.util.zip.ZipInputStream
类名称:ZipInputStream
方法名:closeEntry

ZipInputStream.closeEntry介绍

[英]Closes the current zip entry and prepares to read the next entry.
[中]关闭当前zip条目并准备读取下一个条目。

代码示例

代码示例来源:origin: plantuml/plantuml

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;
}

代码示例来源:origin: airbnb/lottie-android

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();

代码示例来源:origin: zeroturnaround/zt-zip

final ZipInputStream zipIn = new ZipInputStream(pipedIn);
 zipIn.getNextEntry();
 FileUtils.copy(zipIn, destination);
  zipIn.closeEntry();

代码示例来源:origin: plantuml/plantuml

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();
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: javamelody/javamelody

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;
}

代码示例来源:origin: apache/flink

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();
  }
}

代码示例来源:origin: com.h2database/h2

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();

代码示例来源:origin: rapidoid/rapidoid

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);
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

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();

代码示例来源:origin: rapidoid/rapidoid

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;
}

代码示例来源:origin: com.h2database/h2

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);

代码示例来源:origin: ballerina-platform/ballerina-lang

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();

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: graphhopper/graphhopper

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();

代码示例来源:origin: confluentinc/ksql

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(

代码示例来源:origin: plantuml/plantuml

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;
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: googleapis/google-cloud-java

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();

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

@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());
  }
}

相关文章