Search in sources :

Example 31 with ZipException

use of java.util.zip.ZipException in project bnd by bndtools.

the class Domain method domain.

public static Domain domain(File file) throws IOException {
    if (file.getName().endsWith(".mf")) {
        try (InputStream in = IO.stream(file)) {
            Manifest m = new Manifest(in);
            return domain(m);
        }
    }
    if (file.getName().endsWith(".properties") || file.getName().endsWith(".bnd")) {
        Processor p = new Processor();
        p.setProperties(file);
        return domain(p);
    }
    if (file.getName().endsWith(".pom")) {
        try {
            PomParser p = new PomParser();
            p.setProperties(p.getProperties(file));
            return domain(p);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    // default & last. Assume JAR
    try (JarInputStream jin = new JarInputStream(IO.stream(file))) {
        Manifest m = jin.getManifest();
        if (m != null)
            return domain(m);
    }
    try (ZipFile zf = new ZipFile(file)) {
        ZipEntry entry = zf.getEntry("META-INF/MANIFEST.MF");
        if (entry == null)
            return null;
        Manifest m = new Manifest(zf.getInputStream(entry));
        return domain(m);
    } catch (ZipException e) {
        return null;
    }
}
Also used : PomParser(aQute.bnd.maven.PomParser) ZipFile(java.util.zip.ZipFile) JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) Manifest(java.util.jar.Manifest) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Example 32 with ZipException

use of java.util.zip.ZipException in project Payara by payara.

the class AppClientDeployerHelper method copy.

/**
 * copy the entryName element from the source abstract archive into
 * the target abstract archive
 */
static void copy(ReadableArchive source, WritableArchive target, String entryName) throws IOException {
    InputStream is = null;
    OutputStream os = null;
    try {
        is = source.getEntry(entryName);
        if (is != null) {
            try {
                os = target.putNextEntry(entryName);
            } catch (ZipException ze) {
                // this is a duplicate...
                return;
            }
            ArchivistUtils.copyWithoutClose(is, os);
        } else {
            // entryName as a prefix.
            for (Enumeration e = source.entries(entryName); e.hasMoreElements(); ) {
                copy(source, target, (String) e.nextElement());
            }
        }
    } catch (IOException ioe) {
        throw ioe;
    } finally {
        IOException closeEntryIOException = null;
        if (os != null) {
            try {
                target.closeEntry();
            } catch (IOException ioe) {
                closeEntryIOException = ioe;
            }
        }
        if (is != null) {
            is.close();
        }
        if (closeEntryIOException != null) {
            throw closeEntryIOException;
        }
    }
}
Also used : Enumeration(java.util.Enumeration) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException)

Example 33 with ZipException

use of java.util.zip.ZipException in project Payara by payara.

the class Assembler method transferFile.

void transferFile(File file, JarOutputStream jos, String entryName) throws IOException {
    if (file == null || jos == null || entryName == null) {
        return;
    }
    ZipEntry entry = new ZipEntry(entryName);
    try {
        jos.putNextEntry(entry);
    } catch (ZipException ex) {
        return;
    }
    FileInputStream fin = new FileInputStream(file);
    transferContents(fin, jos);
    jos.closeEntry();
}
Also used : ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) FileInputStream(java.io.FileInputStream)

Example 34 with ZipException

use of java.util.zip.ZipException in project pentaho-platform by pentaho.

the class ZipExportProcessor method exportDirectory.

/**
 * @param repositoryDir
 * @param outputStream
 */
@Override
public void exportDirectory(RepositoryFile repositoryDir, OutputStream outputStream, String filePath) throws ExportException, IOException {
    addToManifest(repositoryDir);
    List<RepositoryFile> children = getUnifiedRepository().getChildren(new RepositoryRequest(String.valueOf(repositoryDir.getId()), true, 1, null));
    for (RepositoryFile repositoryFile : children) {
        // exclude 'etc' folder - datasources and etc.
        if (isExportCandidate(repositoryFile.getPath())) {
            if (repositoryFile.isFolder()) {
                if (outputStream.getClass().isAssignableFrom(ZipOutputStream.class)) {
                    ZipOutputStream zos = (ZipOutputStream) outputStream;
                    String zipEntryName = getFixedZipEntryName(repositoryFile, filePath);
                    ZipEntry entry = new ZipEntry(zipEntryName);
                    zos.putNextEntry(entry);
                }
                exportDirectory(repositoryFile, outputStream, filePath);
            } else {
                try {
                    exportFile(repositoryFile, outputStream, filePath);
                } catch (ZipException e) {
                    // possible duplicate entry, log it and continue on with the other files in the directory
                    log.debug(e.getMessage(), e);
                }
            }
        }
    }
    createLocales(repositoryDir, filePath, repositoryDir.isFolder(), outputStream);
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) ZipException(java.util.zip.ZipException)

Example 35 with ZipException

use of java.util.zip.ZipException in project knox by apache.

the class UrlRewriteResponse method streamResponse.

@Override
public void streamResponse(InputStream input, OutputStream output) throws IOException {
    InputStream inStream;
    OutputStream outStream;
    boolean isGzip = false;
    BufferedInputStream inBuffer = new BufferedInputStream(input);
    try {
        // Use this way to check whether the input stream is gzip compressed, in case
        // the content encoding header is unknown, as it could be unset in inbound response
        inBuffer.mark(STREAM_BUFFER_SIZE);
        inStream = new GZIPInputStream(inBuffer);
        isGzip = true;
    } catch (ZipException e) {
        inBuffer.reset();
        inStream = inBuffer;
    } catch (IOException e) {
        inBuffer.reset();
        inStream = inBuffer;
    }
    MimeType mimeType = getMimeType();
    UrlRewriteFilterContentDescriptor filterContentConfig = getRewriteFilterConfig(rewriter.getConfig(), bodyFilterName, mimeType);
    if (filterContentConfig != null) {
        String asType = filterContentConfig.asType();
        if (asType != null && asType.trim().length() > 0) {
            mimeType = MimeTypes.create(asType, getCharacterEncoding());
        }
    }
    InputStream filteredInput = UrlRewriteStreamFilterFactory.create(mimeType, null, inStream, rewriter, this, UrlRewriter.Direction.OUT, filterContentConfig);
    outStream = (isGzip) ? new GZIPOutputStream(output) : output;
    IOUtils.copyLarge(filteredInput, outStream, new byte[STREAM_BUFFER_SIZE]);
    // KNOX-685: outStream.flush();
    outStream.close();
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) MimeType(javax.activation.MimeType) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)

Aggregations

ZipException (java.util.zip.ZipException)188 IOException (java.io.IOException)89 File (java.io.File)71 ZipEntry (java.util.zip.ZipEntry)66 ZipFile (java.util.zip.ZipFile)62 InputStream (java.io.InputStream)45 FileInputStream (java.io.FileInputStream)37 ZipInputStream (java.util.zip.ZipInputStream)26 BufferedInputStream (java.io.BufferedInputStream)22 FileOutputStream (java.io.FileOutputStream)21 JarFile (java.util.jar.JarFile)21 JarEntry (java.util.jar.JarEntry)19 FileNotFoundException (java.io.FileNotFoundException)18 ArrayList (java.util.ArrayList)17 ZipOutputStream (java.util.zip.ZipOutputStream)15 URL (java.net.URL)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 GZIPInputStream (java.util.zip.GZIPInputStream)10 BufferedOutputStream (java.io.BufferedOutputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7