gpt4 book ai didi

java.util.zip.ZipException类的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 12:56:40 30 4
gpt4 key购买 nike

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

ZipException介绍

[英]This runtime exception is thrown by ZipFile and ZipInputStream when the file or stream is not a valid zip file.
[中]当文件或流不是有效的zip文件时,ZipFile和ZipInputStream会引发此运行时异常。

代码示例

代码示例来源:origin: cmusphinx/sphinx4

URI newURI = new URI(absoluteLocation);
  ZipFile zipFile =
      new ZipFile(new File(newURI));
  ZipEntry entry = zipFile.getEntry(file);
  if (entry != null) {
    stream = zipFile.getInputStream(entry);
  zipFile.close();
} catch (URISyntaxException use) {
  use.printStackTrace();
  throw new ZipException("URISyntaxException: " +
      use.getMessage());

代码示例来源:origin: org.apache.ant/ant

return;
try (ZipFile zipf = new ZipFile(f)) {
  Enumeration<? extends ZipEntry> entries = zipf.entries();
  while (entries.hasMoreElements()) {
    ZipEntry inputEntry = entries.nextElement();
    String inputEntryName = inputEntry.getName();
    int index = inputEntryName.indexOf("META-INF");
        if (ex.getMessage().contains("duplicate")) {
      try (InputStream in = zipf.getInputStream(inputEntry)) {
        int len = buffer.length;
        int count = -1;

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

super(codeBaseLocator);
try {
  this.zipFile = new ZipFile(file);
  setLastModifiedTime(file.lastModified());
} catch (IOException e) {
        file.length()));
  ZipException e2 = new ZipException("Error opening zip file " + file + " of " + file.length() + " bytes");
  e2.initCause(e);
  throw e2;

代码示例来源:origin: org.apache.commons/commons-compress

/**
 * Potentially reads more bytes to fill the inflater's buffer and
 * reads from it.
 */
private int readFromInflater(final byte[] buffer, final int offset, final int length) throws IOException {
  int read = 0;
  do {
    if (inf.needsInput()) {
      final int l = fill();
      if (l > 0) {
        current.bytesReadFromStream += buf.limit();
      } else if (l == -1) {
        return -1;
      } else {
        break;
      }
    }
    try {
      read = inf.inflate(buffer, offset, length);
    } catch (final DataFormatException e) {
      throw (IOException) new ZipException(e.getMessage()).initCause(e);
    }
  } while (read == 0 && inf.needsInput());
  return read;
}

代码示例来源:origin: org.apache.commons/commons-compress

switch(onUnparseableData.getKey()) {
case UnparseableExtraField.THROW_KEY:
  throw new ZipException("bad extra field starting at "
              + start + ".  Block length of "
              + length + " bytes exceeds remaining"
  throw new ZipException("unknown UnparseableExtraField key: "
              + onUnparseableData.getKey());
  throw (ZipException) new ZipException("Failed to parse corrupt ZIP extra field of type "
    + Integer.toHexString(headerId.getValue())).initCause(aiobe);
throw (ZipException) new ZipException(ie.getMessage()).initCause(ie);

代码示例来源:origin: org.apache.cxf/cxf-common-utilities

private List<String> load(File jarFile) throws IOException {
  List<String> jarContents = new ArrayList<String>();
  try {
    ZipFile zf = new ZipFile(jarFile);
    for (Enumeration e = zf.entries(); e.hasMoreElements();) {
      ZipEntry ze = (ZipEntry) e.nextElement();
      if (ze.isDirectory()) {
        continue;
      }
      jarContents.add(ze.getName());
    }
  } catch (NullPointerException e) {
    System.out.println("done.");
  } catch (ZipException ze) {
    ze.printStackTrace();
  }
  return jarContents;
}

代码示例来源:origin: biz.aQute.bnd/bndlib

public static ZipFile build(Jar jar, File file, Pattern pattern) throws ZipException, IOException {
  try {
    ZipFile zip = new ZipFile(file);
    nextEntry: for (Enumeration< ? extends ZipEntry> e = zip.entries(); e.hasMoreElements();) {
      ZipEntry entry = e.nextElement();
      if (pattern != null) {
        Matcher m = pattern.matcher(entry.getName());
        if (!m.matches())
          continue nextEntry;
      }
      if (!entry.isDirectory()) {
        jar.putResource(entry.getName(), new ZipResource(zip, entry), true);
      }
    }
    return zip;
  }
  catch (ZipException ze) {
    throw new ZipException("The JAR/ZIP file (" + file.getAbsolutePath() + ") seems corrupted, error: "
        + ze.getMessage());
  }
  catch (FileNotFoundException e) {
    throw new IllegalArgumentException("Problem opening JAR: " + file.getAbsolutePath());
  }
}

代码示例来源:origin: net.open-esb.core/manage

/**
 * Unzips a file.
 *
 * @param zpFile File to be unzipped
 * @throws IOException if error trying to read entry.
 * @throws java.util.zip.ZipException if error trying to read zip file.
 */
public void unZip (File zpFile) throws IOException, ZipException
{
  
  if (!zpFile.getName ().endsWith (".zip"))
  {
    throw new ZipException ("Not a zip file? " + zpFile.getName ());
  }
  
  // process all entries in that JAR file
  ZipFile zp = new ZipFile (zpFile);
  Enumeration all = zp.entries ();
  while (all.hasMoreElements ())
  {
    getEntry (zp, ((ZipEntry) (all.nextElement ())));
  }
  
  zp.close ();
}

代码示例来源:origin: deathmarine/Luyten

Set<String> history = new HashSet<String>();
int tick = 0;
while (ent.hasMoreElements() && !cancel) {
  bar.setValue(++tick);
  JarEntry entry = ent.nextElement();
  if (!mass.contains(entry.getName()))
    continue;
      if (!ze.getMessage().contains("duplicate")) {
        throw ze;

代码示例来源:origin: biz.aQute.bnd/biz.aQute.bndlib

private Jar buildFromZip(File file) throws IOException {
  try {
    zipFile = new ZipFile(file);
    for (ZipEntry entry : Iterables.iterable(zipFile.entries())) {
      if (entry.isDirectory()) {
        continue;
      }
      putResource(entry.getName(), new ZipResource(zipFile, entry), true);
    }
    return this;
  } catch (ZipException e) {
    IO.close(zipFile);
    ZipException ze = new ZipException(
      "The JAR/ZIP file (" + file.getAbsolutePath() + ") seems corrupted, error: " + e.getMessage());
    ze.initCause(e);
    throw ze;
  } catch (FileNotFoundException e) {
    IO.close(zipFile);
    throw new IllegalArgumentException("Problem opening JAR: " + file.getAbsolutePath(), e);
  } catch (IOException e) {
    IO.close(zipFile);
    throw e;
  }
}

代码示例来源:origin: TechnicPack/LauncherCore

public static boolean extractFile(File zip, File output, String fileName) throws IOException, InterruptedException {
  if (!zip.exists() || fileName == null) {
    return false;
  }
  ZipFile zipFile = null;
  try {
    zipFile = new ZipFile(zip);
    ZipEntry entry = zipFile.getEntry(fileName);
    if (entry == null) {
      Utils.getLogger().log(Level.WARNING, "File " + fileName + " not found in " + zip.getAbsolutePath());
      return false;
    }
    File outputFile = new File(output, entry.getName());
    if (outputFile.getParentFile() != null) {
      outputFile.getParentFile().mkdirs();
    }
    unzipEntry(zipFile, zipFile.getEntry(fileName), outputFile);
    return true;
  } catch (ZipException e) {
    e.printStackTrace();
    throw new ZipException("Error extracting file " + zip.getName());
  } catch (IOException e) {
    Utils.getLogger().log(Level.WARNING, "Error extracting file " + fileName + " from " + zip.getAbsolutePath());
    return false;
  } finally {
    if (zipFile != null) {
      zipFile.close();
    }
  }
}

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

entry = getEntry(entry.getName());
if (entry == null) {
  return null;
    throwZipException("Local File Header", localMagic);
    throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
  } else {
    rafStream.endOffset = rafStream.offset + entry.compressedSize;
    int bufSize = Math.max(1024, (int) Math.min(entry.getSize(), 65535L));
    return new ZipInflaterInputStream(rafStream, new Inflater(true), bufSize, entry);

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

throw new ZipException("File too short to be a zip file: " + raf.length());
final int headerMagic = Integer.reverseBytes(raf.readInt());
if (headerMagic != LOCSIG) {
  throw new ZipException("Not a zip archive");
    throw new ZipException("End Of Central Directory signature not found");
  throw new ZipException("Spanned archives not supported");
byte[] hdrBuf = new byte[CENHDR]; // Reuse the same buffer for each entry.
for (int i = 0; i < numEntries; ++i) {
  ZipEntry newEntry = new ZipEntry(hdrBuf, bufferedStream);
  if (newEntry.localHeaderRelOffset >= centralDirOffset) {
    throw new ZipException("Local file header offset is after central directory");
  String entryName = newEntry.getName();
  if (entries.put(entryName, newEntry) != null) {
    throw new ZipException("Duplicate entry name: " + entryName);

代码示例来源:origin: org.apache.curator/curator-framework

Inflater inflater = acquireInflater();
try {
  inflater.setInput(gzippedDataBytes, headerSize, compressedDataSize);
  CRC32 crc = new CRC32();
  int offset = 0;
  while (true)
      numDecompressedBytes = inflater.inflate(result, offset, result.length - offset);
    } catch (DataFormatException e) {
      String s = e.getMessage();
      throw new ZipException(s != null ? s : "Invalid ZLIB data format");
    crc.update(result, offset, numDecompressedBytes);
    offset += numDecompressedBytes;
    if ( inflater.finished() || inflater.needsDictionary() )
    else if ( numDecompressedBytes == 0 && inflater.needsInput() )
      throw new ZipException("Corrupt GZipped data");
  if ( inflater.getRemaining() != 0 )
    throw new ZipException("Expected just one GZip block, without garbage in the end");
  if ( checksum != (int) crc.getValue() || numUncompressedBytes != offset )
    throw new ZipException("Corrupt GZIP trailer");

代码示例来源:origin: org.apache.ant/ant

byte[] tmp = new byte[length - WORD];
System.arraycopy(data, offset + WORD, tmp, 0, length - WORD);
crc.reset();
crc.update(tmp);
long realChecksum = crc.getValue();
if (givenChecksum != realChecksum) {
  throw new ZipException("bad CRC checksum "
              + Long.toHexString(givenChecksum)
              + " instead of "

代码示例来源:origin: blynkkk/blynk-server

private void addZipEntryAndWrite(ZipOutputStream zipStream,
                  String onePinFileName, byte[] onePinDataCsv) throws IOException {
  ZipEntry zipEntry = new ZipEntry(onePinFileName);
  try {
    zipStream.putNextEntry(zipEntry);
    zipStream.write(onePinDataCsv);
    zipStream.closeEntry();
  } catch (ZipException zipException) {
    String message = zipException.getMessage();
    if (message != null && message.contains("duplicate")) {
      log.warn("Duplicate zip entry {}. Wrong report configuration.", onePinFileName);
    } else {
      log.error("Error compressing report file.", message);
      throw zipException;
    }
  } catch (IOException e) {
    log.error("Error compressing report file.", e.getMessage());
    throw e;
  }
}

代码示例来源:origin: org.apache.curator/curator-framework

private static int doReadHeader(ByteBuffer gzippedData) throws IOException {
  if ( gzippedData.getChar() != GZIP_MAGIC )
    throw new ZipException("Not in GZip format");
    throw new ZipException("Unsupported compression method");
    CRC32 crc = new CRC32();
    crc.update(gzippedData.array(), 0, gzippedData.position());
    if ( gzippedData.getChar() != (char) crc.getValue() )
      throw new ZipException("Corrupt GZIP header");

代码示例来源:origin: cmusphinx/sphinx4

stream = new ZipOutputStream(new BufferedOutputStream(fos));
  ZipEntry entry = new ZipEntry(file);
  ((ZipOutputStream) stream).putNextEntry(entry);
} catch (URISyntaxException use) {
  use.printStackTrace();
  throw new ZipException("URISyntaxException: " +
      use.getMessage());

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

Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
if (inf.finished() || currentEntry == null) {
  return -1;
  lastRead += toRead;
  inRead += toRead;
  crc.update(buffer, byteOffset, toRead);
  return toRead;
if (inf.needsInput()) {
  fill();
  if (len > 0) {
  read = inf.inflate(buffer, byteOffset, byteCount);
} catch (DataFormatException e) {
  throw new ZipException(e.getMessage());
if (read == 0 && inf.finished()) {
  return -1;
crc.update(buffer, byteOffset, read);
return read;

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

private void readAndVerifyDataDescriptor(int inB, int out) throws IOException {
  if (hasDD) {
    Streams.readFully(in, hdrBuf, 0, EXTHDR);
    int sig = Memory.peekInt(hdrBuf, 0, ByteOrder.LITTLE_ENDIAN);
    if (sig != (int) EXTSIG) {
      throw new ZipException(String.format("unknown format (EXTSIG=%x)", sig));
    }
    currentEntry.crc = ((long) Memory.peekInt(hdrBuf, EXTCRC, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
    currentEntry.compressedSize = ((long) Memory.peekInt(hdrBuf, EXTSIZ, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
    currentEntry.size = ((long) Memory.peekInt(hdrBuf, EXTLEN, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
  }
  if (currentEntry.crc != crc.getValue()) {
    throw new ZipException("CRC mismatch");
  }
  if (currentEntry.compressedSize != inB || currentEntry.size != out) {
    throw new ZipException("Size mismatch");
  }
}

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com