Search in sources :

Example 96 with JarInputStream

use of java.util.jar.JarInputStream in project flink by apache.

the class JarHelper method unjar.

/**
	 * Given an InputStream on a jar file, unjars the contents into the given
	 * directory.
	 */
public void unjar(InputStream in, File destDir) throws IOException {
    BufferedOutputStream dest = null;
    JarInputStream jis = new JarInputStream(in);
    JarEntry entry;
    while ((entry = jis.getNextJarEntry()) != null) {
        if (entry.isDirectory()) {
            File dir = new File(destDir, entry.getName());
            dir.mkdir();
            if (entry.getTime() != -1) {
                dir.setLastModified(entry.getTime());
            }
            continue;
        }
        int count;
        byte[] data = new byte[BUFFER_SIZE];
        File destFile = new File(destDir, entry.getName());
        if (mVerbose) {
            System.out.println("unjarring " + destFile + " from " + entry.getName());
        }
        FileOutputStream fos = new FileOutputStream(destFile);
        dest = new BufferedOutputStream(fos, BUFFER_SIZE);
        try {
            while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) {
                dest.write(data, 0, count);
            }
            dest.flush();
        } finally {
            dest.close();
        }
        if (entry.getTime() != -1) {
            destFile.setLastModified(entry.getTime());
        }
    }
    jis.close();
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileOutputStream(java.io.FileOutputStream) JarEntry(java.util.jar.JarEntry) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 97 with JarInputStream

use of java.util.jar.JarInputStream in project robovm by robovm.

the class OldJarInputStreamTest method test_ConstructorLjava_io_InputStreamZ.

public void test_ConstructorLjava_io_InputStreamZ() {
    try {
        // we need a buffered stream because ByteArrayInputStream.close() is a no-op
        InputStream is = new BufferedInputStream(new ByteArrayInputStream(new byte[0]));
        is.close();
        new JarInputStream(is, false);
        fail("IOException expected");
    } catch (IOException ee) {
    // expected
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 98 with JarInputStream

use of java.util.jar.JarInputStream in project robovm by robovm.

the class OldJarInputStreamTest method test_read$ZII.

public void test_read$ZII() throws Exception {
    File resources = Support_Resources.createTempFolder();
    Support_Resources.copyFile(resources, null, "Broken_entry_data.jar");
    InputStream is = Support_Resources.getStream("Broken_entry_data.jar");
    JarInputStream jis = new JarInputStream(is, true);
    byte[] b = new byte[100];
    jis.getNextEntry();
    jis.read(b, 0, 100);
    jis.getNextEntry();
    jis.getNextEntry();
    jis.getNextEntry();
    try {
        jis.read(b, 0, 100);
        fail("ZipException expected");
    } catch (ZipException ee) {
    // expected
    }
    try {
        // Android throws exception here, already!
        jis.close();
        // But RI here, only!
        jis.read(b, 0, 100);
        fail("IOException expected");
    } catch (IOException ee) {
    // expected
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) File(java.io.File)

Example 99 with JarInputStream

use of java.util.jar.JarInputStream in project reflections by ronmamo.

the class JarInputDir method getFiles.

public Iterable<Vfs.File> getFiles() {
    return new Iterable<Vfs.File>() {

        public Iterator<Vfs.File> iterator() {
            return new AbstractIterator<Vfs.File>() {

                {
                    try {
                        jarInputStream = new JarInputStream(url.openConnection().getInputStream());
                    } catch (Exception e) {
                        throw new ReflectionsException("Could not open url connection", e);
                    }
                }

                protected Vfs.File computeNext() {
                    while (true) {
                        try {
                            ZipEntry entry = jarInputStream.getNextJarEntry();
                            if (entry == null) {
                                return endOfData();
                            }
                            long size = entry.getSize();
                            //JDK-6916399
                            if (size < 0)
                                size = 0xffffffffl + size;
                            nextCursor += size;
                            if (!entry.isDirectory()) {
                                return new JarInputFile(entry, JarInputDir.this, cursor, nextCursor);
                            }
                        } catch (IOException e) {
                            throw new ReflectionsException("could not get next zip entry", e);
                        }
                    }
                }
            };
        }
    };
}
Also used : ReflectionsException(org.reflections.ReflectionsException) JarInputStream(java.util.jar.JarInputStream) ZipEntry(java.util.zip.ZipEntry) AbstractIterator(com.google.common.collect.AbstractIterator) IOException(java.io.IOException) ReflectionsException(org.reflections.ReflectionsException) IOException(java.io.IOException)

Example 100 with JarInputStream

use of java.util.jar.JarInputStream in project spring-boot by spring-projects.

the class JarFile method setupEntryCertificates.

void setupEntryCertificates(JarEntry entry) {
    // happening that often.
    try {
        JarInputStream inputStream = new JarInputStream(getData().getInputStream(ResourceAccess.ONCE));
        try {
            java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry();
            while (certEntry != null) {
                inputStream.closeEntry();
                if (entry.getName().equals(certEntry.getName())) {
                    setCertificates(entry, certEntry);
                }
                setCertificates(getJarEntry(certEntry.getName()), certEntry);
                certEntry = inputStream.getNextJarEntry();
            }
        } finally {
            inputStream.close();
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) IOException(java.io.IOException)

Aggregations

JarInputStream (java.util.jar.JarInputStream)154 JarEntry (java.util.jar.JarEntry)72 IOException (java.io.IOException)66 FileInputStream (java.io.FileInputStream)63 Manifest (java.util.jar.Manifest)50 File (java.io.File)46 InputStream (java.io.InputStream)45 ZipEntry (java.util.zip.ZipEntry)29 JarOutputStream (java.util.jar.JarOutputStream)27 FileOutputStream (java.io.FileOutputStream)24 ByteArrayInputStream (java.io.ByteArrayInputStream)22 URL (java.net.URL)20 Test (org.junit.Test)20 OutputStream (java.io.OutputStream)13 JarFile (java.util.jar.JarFile)13 BufferedInputStream (java.io.BufferedInputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ArrayList (java.util.ArrayList)10 Attributes (java.util.jar.Attributes)10 HashSet (java.util.HashSet)8