Search in sources :

Example 31 with ZipInputStream

use of java.util.zip.ZipInputStream in project NabAlive by jcheype.

the class ApplicationGroovyLoader method registerZip.

private void registerZip(File file) throws IOException, InstantiationException, IllegalAccessException {
    ZipInputStream zipinputstream = new ZipInputStream(new FileInputStream(file));
    String name = stripExtension(file.getName());
    Application application = null;
    byte[] logo = null;
    String descriptor = null;
    ZipEntry zipentry = zipinputstream.getNextEntry();
    while (zipentry != null) {
        String entryName = zipentry.getName();
        if ("main.groovy".equalsIgnoreCase(entryName)) {
            application = loadApplication(zipentry, zipinputstream, name);
        } else if ("icon.png".equalsIgnoreCase(entryName)) {
            logo = loadLogo(zipentry, zipinputstream);
        } else if ("descriptor.json".equalsIgnoreCase(entryName)) {
            descriptor = loadDescriptor(zipentry, zipinputstream);
        }
        zipinputstream.closeEntry();
        zipentry = zipinputstream.getNextEntry();
    }
    zipinputstream.close();
    if (application != null && logo != null && descriptor != null) {
        applicationManager.registerApp(application, name, descriptor, logo);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileInputStream(java.io.FileInputStream)

Example 32 with ZipInputStream

use of java.util.zip.ZipInputStream in project neo4j by neo4j.

the class ProcedureJarLoader method listClassesIn.

private RawIterator<Class<?>, IOException> listClassesIn(URL jar, ClassLoader loader) throws IOException {
    ZipInputStream zip = new ZipInputStream(jar.openStream());
    return new PrefetchingRawIterator<Class<?>, IOException>() {

        @Override
        protected Class<?> fetchNextOrNull() throws IOException {
            try {
                while (true) {
                    ZipEntry nextEntry = zip.getNextEntry();
                    if (nextEntry == null) {
                        zip.close();
                        return null;
                    }
                    String name = nextEntry.getName();
                    if (name.endsWith(".class")) {
                        String className = name.substring(0, name.length() - ".class".length()).replace("/", ".");
                        try {
                            Class<?> aClass = loader.loadClass(className);
                            // We do getDeclaredMethods to trigger NoClassDefErrors, which loadClass above does
                            // not do.
                            // This way, even if some of the classes in a jar cannot be loaded, we still check
                            // the others.
                            aClass.getDeclaredMethods();
                            return aClass;
                        } catch (UnsatisfiedLinkError | NoClassDefFoundError | Exception e) {
                            log.warn("Failed to load `%s` from plugin jar `%s`: %s", className, jar.getFile(), e.getMessage());
                        }
                    }
                }
            } catch (IOException | RuntimeException e) {
                zip.close();
                throw e;
            }
        }
    };
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) PrefetchingRawIterator(org.neo4j.collection.PrefetchingRawIterator) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 33 with ZipInputStream

use of java.util.zip.ZipInputStream in project nutz by nutzam.

the class JarResource method getInputStream.

public InputStream getInputStream() throws IOException {
    ZipInputStream zis = Scans.makeZipInputStream(jarPath);
    ZipEntry ens = null;
    while (null != (ens = zis.getNextEntry())) {
        if (ens.getName().equals(entryName))
            return zis;
    }
    throw Lang.impossible();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry)

Example 34 with ZipInputStream

use of java.util.zip.ZipInputStream in project orientdb by orientechnologies.

the class OZIPCompressionUtil method uncompressDirectory.

/***
   * Extract zipfile to outdir with complete directory structure
   */
public static void uncompressDirectory(final InputStream in, final String out, final OCommandOutputListener iListener) throws IOException {
    final File outdir = new File(out);
    final ZipInputStream zin = new ZipInputStream(in);
    try {
        ZipEntry entry;
        String name, dir;
        while ((entry = zin.getNextEntry()) != null) {
            name = entry.getName();
            if (entry.isDirectory()) {
                mkdirs(outdir, name);
                continue;
            }
            /*
         * this part is necessary because file entry can come before directory entry where is file located i.e.: /foo/foo.txt /foo/
         */
            dir = getDirectoryPart(name);
            if (dir != null)
                mkdirs(outdir, dir);
            extractFile(zin, outdir, name, iListener);
        }
    } finally {
        zin.close();
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File)

Example 35 with ZipInputStream

use of java.util.zip.ZipInputStream in project orientdb by orientechnologies.

the class OZIPCompression method uncompress.

@Override
public byte[] uncompress(final byte[] content, final int offset, final int length) {
    try {
        final OMemoryInputStream memoryInputStream = new OMemoryInputStream(content, offset, length);
        // 16KB
        final ZipInputStream gzipInputStream = new ZipInputStream(memoryInputStream);
        try {
            final byte[] buffer = new byte[1024];
            byte[] result = new byte[1024];
            int bytesRead;
            ZipEntry entry = gzipInputStream.getNextEntry();
            int len = 0;
            while ((bytesRead = gzipInputStream.read(buffer, 0, buffer.length)) > -1) {
                if (len + bytesRead > result.length) {
                    int newSize = 2 * result.length;
                    if (newSize < len + bytesRead)
                        newSize = Integer.MAX_VALUE;
                    final byte[] oldResult = result;
                    result = new byte[newSize];
                    System.arraycopy(oldResult, 0, result, 0, oldResult.length);
                }
                System.arraycopy(buffer, 0, result, len, bytesRead);
                len += bytesRead;
            }
            return Arrays.copyOf(result, len);
        } finally {
            gzipInputStream.close();
        }
    } catch (IOException ioe) {
        throw new IllegalStateException("Exception during data uncompression", ioe);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)354 ZipEntry (java.util.zip.ZipEntry)259 FileInputStream (java.io.FileInputStream)120 File (java.io.File)115 IOException (java.io.IOException)103 ByteArrayInputStream (java.io.ByteArrayInputStream)63 FileOutputStream (java.io.FileOutputStream)63 ByteArrayOutputStream (java.io.ByteArrayOutputStream)62 Test (org.junit.Test)56 InputStream (java.io.InputStream)53 BufferedInputStream (java.io.BufferedInputStream)47 ZipOutputStream (java.util.zip.ZipOutputStream)31 FileNotFoundException (java.io.FileNotFoundException)21 Path (java.nio.file.Path)20 HashMap (java.util.HashMap)19 BufferedOutputStream (java.io.BufferedOutputStream)18 ArrayList (java.util.ArrayList)18 ZipFile (java.util.zip.ZipFile)18 OutputStream (java.io.OutputStream)17 GZIPInputStream (java.util.zip.GZIPInputStream)14