Refine search
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());
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;
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;
/** * 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; }
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);
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; }
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()); } }
/** * 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 (); }
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;
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; } }
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(); } } }
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);
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);
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");
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 "
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; } }
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");
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());
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;
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"); } }