Search in sources :

Example 96 with ZipException

use of java.util.zip.ZipException in project che by eclipse.

the class JavaModelManager method verifyArchiveContent.

public void verifyArchiveContent(IPath path) throws CoreException {
    if (isInvalidArchive(path)) {
        throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.status_IOException, new ZipException()));
    }
    ZipFile file = getZipFile(path);
    closeZipFile(file);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IJavaModelStatus(org.eclipse.jdt.core.IJavaModelStatus) CoreException(org.eclipse.core.runtime.CoreException) ZipFile(java.util.zip.ZipFile) ZipException(java.util.zip.ZipException)

Example 97 with ZipException

use of java.util.zip.ZipException in project buck by facebook.

the class OverwritingZipOutputStream method actuallyPutNextEntry.

@Override
protected void actuallyPutNextEntry(ZipEntry entry) throws IOException {
    // We calculate the actual offset when closing the stream, so 0 is fine.
    currentEntry = new EntryAccounting(clock, entry, /* currentOffset */
    0);
    long md5 = Hashing.md5().hashUnencodedChars(entry.getName()).asLong();
    String name = String.valueOf(md5);
    File file = new File(scratchDir, name);
    entries.put(file, currentEntry);
    if (file.exists() && !file.delete()) {
        throw new ZipException("Unable to delete existing file: " + entry.getName());
    }
    currentOutput = new BufferedOutputStream(new FileOutputStream(file));
}
Also used : FileOutputStream(java.io.FileOutputStream) ZipException(java.util.zip.ZipException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 98 with ZipException

use of java.util.zip.ZipException in project buck by facebook.

the class JarDirectoryStepHelper method copyZipEntriesToJar.

/**
   * @param inputFile is assumed to be a zip
   * @param outputFile the path where output is being written to
   * @param jar is the stream to write to
   * @param alreadyAddedEntries is used to avoid duplicate entries.
   */
private static void copyZipEntriesToJar(Path inputFile, Path outputFile, final CustomZipOutputStream jar, Set<String> alreadyAddedEntries, JavacEventSink eventSink, Iterable<Pattern> blacklist) throws IOException {
    try (ZipFile zip = new ZipFile(inputFile.toFile())) {
        for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements(); ) {
            ZipEntry entry = entries.nextElement();
            String entryName = entry.getName();
            // We already read the manifest. No need to read it again
            if (JarFile.MANIFEST_NAME.equals(entryName)) {
                continue;
            }
            // Check if the entry belongs to the blacklist and it should be excluded from the Jar.
            if (shouldEntryBeRemovedFromJar(eventSink, entryName, blacklist)) {
                continue;
            }
            // duplicate class files.
            if (!isDuplicateAllowed(entryName) && !alreadyAddedEntries.add(entryName)) {
                // Duplicate entries. Skip.
                eventSink.reportEvent(determineSeverity(entry), "Duplicate found when adding '%s' to '%s' from '%s'", entryName, outputFile.toAbsolutePath(), inputFile.toAbsolutePath());
                continue;
            }
            ZipEntry newEntry = new ZipEntry(entry);
            // See https://github.com/spearce/buck/commit/8338c1c3d4a546f577eed0c9941d9f1c2ba0a1b7.
            if (entry.getMethod() == ZipEntry.DEFLATED) {
                newEntry.setCompressedSize(-1);
            }
            jar.putNextEntry(newEntry);
            try (InputStream inputStream = zip.getInputStream(entry)) {
                ByteStreams.copy(inputStream, jar);
            }
            jar.closeEntry();
        }
    } catch (ZipException e) {
        throw new IOException("Failed to process zip file " + inputFile + ": " + e.getMessage(), e);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Example 99 with ZipException

use of java.util.zip.ZipException in project jetty.project by eclipse.

the class CompressExtension method outgoingFrame.

@Override
public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode) {
    if (flusher.isFailed()) {
        notifyCallbackFailure(callback, new ZipException());
        return;
    }
    FrameEntry entry = new FrameEntry(frame, callback, batchMode);
    if (LOG.isDebugEnabled())
        LOG.debug("Queuing {}", entry);
    offerEntry(entry);
    flusher.iterate();
}
Also used : ZipException(java.util.zip.ZipException)

Example 100 with ZipException

use of java.util.zip.ZipException in project j2objc by google.

the class AbstractZipFileTest method testConstructorFailsWhenReadingEmptyZipArchive.

/**
     * RI does not allow reading of an empty zip using a {@link ZipFile}.
     */
public void testConstructorFailsWhenReadingEmptyZipArchive() throws IOException {
    File resources = Support_Resources.createTempFolder();
    File emptyZip = Support_Resources.copyFile(resources, "java/util/zip", "EmptyArchive.zip");
    try {
        // The following should fail with an exception but if it doesn't then we need to clean
        // up the resource so we need a reference to it.
        ZipFile zipFile = new ZipFile(emptyZip);
        // Clean up the resource.
        try {
            zipFile.close();
        } catch (Exception e) {
        // Ignore
        }
        fail();
    } catch (ZipException expected) {
    // expected
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ZipException(java.util.zip.ZipException) File(java.io.File) ZipFile(java.util.zip.ZipFile) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Aggregations

ZipException (java.util.zip.ZipException)197 IOException (java.io.IOException)96 File (java.io.File)74 ZipEntry (java.util.zip.ZipEntry)67 ZipFile (java.util.zip.ZipFile)63 InputStream (java.io.InputStream)50 FileInputStream (java.io.FileInputStream)39 ZipInputStream (java.util.zip.ZipInputStream)26 FileOutputStream (java.io.FileOutputStream)23 BufferedInputStream (java.io.BufferedInputStream)22 JarFile (java.util.jar.JarFile)21 FileNotFoundException (java.io.FileNotFoundException)19 JarEntry (java.util.jar.JarEntry)19 ArrayList (java.util.ArrayList)18 ByteArrayInputStream (java.io.ByteArrayInputStream)15 ZipOutputStream (java.util.zip.ZipOutputStream)15 URL (java.net.URL)14 GZIPInputStream (java.util.zip.GZIPInputStream)12 BufferedOutputStream (java.io.BufferedOutputStream)8 RandomAccessFile (java.io.RandomAccessFile)8