Package java.util.jar

Examples of java.util.jar.JarInputStream


    private void assertJarContents(Manifest man) throws IOException
    {
        File indexFile = new File(m_tempDir, "index.txt");

        FileInputStream fis = new FileInputStream(m_jarFile);
        JarInputStream jis = new ContentCopyingJarInputStream(fis, indexFile, m_tempDir);

        try
        {
            JarEntry entry;
            while ((entry = jis.getNextJarEntry()) != null)
            {
                File f = new File(m_tempDir, entry.getName());

                // Without reading the actual contents, the copy should already exist...
                assertTrue(entry.getName() + " does not exist?!", f.exists());

                int size = (INDEX_NAME.equals(entry.getName()) ? 33 : 1024);

                byte[] input = new byte[size];
                int read = jis.read(input);

                assertEquals("Not all bytes were read: " + entry.getName(), size, read);

                // Contents will only be completely written after closing the JAR entry itself...
                jis.closeEntry();

                verifyContents(f, input);
            }

            assertEquals("Manifest not as expected", man, jis.getManifest());
        }
        finally
        {
            jis.close();
        }
    }
View Full Code Here


                                    LOGGER.error(MessageFormat.format("Error closing stream: {0}", e.getMessage()), e);
                                }
                            }
                        }

                        JarInputStream jis = null;
                        try {
                            URLConnection urlConnection = url.openConnection();
                            urlConnection.setUseCaches(false);

                            if (urlConnection instanceof JarURLConnection) {
                                JarURLConnection jarUrlConnection = (JarURLConnection) urlConnection;
                                return jarUrlConnection.getManifest();
                            } else {
                                jis = new JarInputStream(urlConnection.getInputStream());
                                return jis.getManifest();
                            }
                        } catch (IOException e) {
                            LOGGER.error(MessageFormat.format("Error reading META-INF/MANIFEST.MF file: {0}", e.getMessage()),
                                e);
                        } finally {
                            if (jis != null) {
                                try {
                                    jis.close();
                                } catch (IOException e) {
                                    LOGGER.error(MessageFormat.format("Error closing stream: {0}", e.getMessage()), e);
                                }
                            }
                        }
View Full Code Here

        LumifyProperties.CONCEPT_TYPE.setProperty(data.getElement(), Ontology.CONCEPT_TYPE_JAR_FILE, data.getProperty().getVisibility(), getAuthorizations());
        LumifyProperties.MIME_TYPE.setProperty(data.getElement(), "application/java-archive", data.getProperty().getVisibility(), getAuthorizations());

        List<Vertex> existingFileVerticies = toList(((Vertex) data.getElement()).getVertices(Direction.BOTH, Ontology.EDGE_LABEL_JAR_CONTAINS, getAuthorizations()));

        JarInputStream jarInputStream = new JarInputStream(in);
        JarEntry jarEntry;
        while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
            if (jarEntry.isDirectory()) {
                continue;
            }

            if (fileAlreadyExists(existingFileVerticies, jarEntry.getName())) {
View Full Code Here

        return readFromJar( new ByteArrayInputStream( jarFile ) );
    }
   
    public static MemoryFileSystem readFromJar(InputStream jarFile) {
        MemoryFileSystem mfs = new MemoryFileSystem();
        JarInputStream zipFile = null;
        try {
            zipFile = new JarInputStream( jarFile );
            ZipEntry entry = null;
            while ( (entry = zipFile.getNextEntry()) != null ) {
                // entry.getSize() is not accurate according to documentation, so have to read bytes until -1 is found
                ByteArrayOutputStream content = new ByteArrayOutputStream();
                int b = -1;
                while( (b = zipFile.read()) != -1 ) {
                    content.write( b );
                }
                mfs.write( entry.getName(), content.toByteArray(), true );
            }
        } catch ( IOException e ) {
            throw new RuntimeException( e );
        } finally {
            if ( zipFile != null ) {
                try {
                    zipFile.close();
                } catch ( IOException e ) { }
            }
        }
        return mfs;
    }
View Full Code Here

     */
    public static void killMetaInf () {
        File inputFile = new File(Settings.getSettings().getInstallPath() + "/" + ModPack.getSelectedPack().getDir() + "/minecraft/bin", "minecraft.jar");
        File outputTmpFile = new File(Settings.getSettings().getInstallPath() + "/" + ModPack.getSelectedPack().getDir() + "/minecraft/bin", "minecraft.jar.tmp");
        try {
            JarInputStream input = new JarInputStream(new FileInputStream(inputFile));
            JarOutputStream output = new JarOutputStream(new FileOutputStream(outputTmpFile));
            JarEntry entry;

            while ((entry = input.getNextJarEntry()) != null) {
                if (entry.getName().contains("META-INF")) {
                    continue;
                }
                output.putNextEntry(entry);
                byte buffer[] = new byte[1024];
                int amo;
                while ((amo = input.read(buffer, 0, 1024)) != -1) {
                    output.write(buffer, 0, amo);
                }
                output.closeEntry();
            }

            input.close();
            output.close();

            if (!inputFile.delete()) {
                Logger.logError("Failed to delete Minecraft.jar.");
                return;
View Full Code Here

    TYPE getThis() {
        return (TYPE) this;
    }

    void retrieveAndSetBundleInformation() throws RuntimeException {
        JarInputStream jis = null;
        try {
            jis = new JarInputStream(m_url.openStream());

            Manifest bundleManifest = jis.getManifest();
            if (bundleManifest == null) {
                throw new RuntimeException("Not a valid manifest in: " + m_url);
            }

            Attributes attributes = bundleManifest.getMainAttributes();

            if (m_symbolicName == null || "".equals(m_symbolicName.trim())) {
                setSymbolicName(getRequiredHeader(attributes, "Bundle-SymbolicName"));
            }

            if (m_version == null || "".equals(m_version.trim())) {
                setVersion(getRequiredHeader(attributes, "Bundle-Version"));
            }
           
            if (m_filename == null || "".equals(m_filename.trim())) {
                setFilename(new File(m_url.getFile()).getName());
            }
           
            setAdditionalBundleInformation(bundleManifest);
        }
        catch (IOException exception) {
            throw new RuntimeException("Failed to retrieve bundle information; set symbolic name and version!", exception);
        }
        finally {
            if (jis != null) {
                try {
                    jis.close();
                }
                catch (IOException exception) {
                    // Ignore...
                }
            }
View Full Code Here

    public abstract static class JarManifestFilter implements ResourceFilter {

        public final InputStream createInputStream(URL url) throws IOException {
            byte[] buffer = new byte[BUFFER_SIZE];

            JarInputStream jis = new JarInputStream(url.openStream());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            JarOutputStream jos = new JarOutputStream(baos, filterManifest(jis.getManifest()));

            JarEntry input;
            while ((input = jis.getNextJarEntry()) != null) {
                jos.putNextEntry(input);
                int read;
                while ((read = jis.read(buffer)) > 0) {
                    jos.write(buffer, 0, read);
                }
                jos.closeEntry();
            }
            jos.close();
            jis.close();

            return new ByteArrayInputStream(baos.toByteArray());
        }
View Full Code Here

            .setFixPackage()
            .add(dpBuilder.createBundleResource()
                .setUrl(getTestBundle("bundle1")).setMissing()
            );

        JarInputStream jis = new JarInputStream(dpBuilder.generate());
        assertNotNull(jis);

        Manifest manifest = jis.getManifest();
        assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
        assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");

        String filename = getBundleName("bundle1");
View Full Code Here

        dpBuilder
            .add(dpBuilder.createBundleResource()
                .setUrl(getTestBundle("bundle1"))
            );

        JarInputStream jis = new JarInputStream(dpBuilder.generate());
        assertNotNull(jis);

        Manifest manifest = jis.getManifest();
        assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
        assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");

        String filename = getBundleName("bundle1");
View Full Code Here

            .add(dpBuilder.createBundleResource()
                .setVersion("1.1.0")
                .setFilter(new JarManifestManipulatingFilter("Bundle-Version", "1.1.0", "Foo", "bar"))
                .setUrl(getTestBundle("bundle1")));

        JarInputStream jis = new JarInputStream(dpBuilder.generate());
        assertNotNull(jis);

        Manifest manifest = jis.getManifest();
        assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
        assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");

        String filename = getBundleName("bundle1");

        assertManifestEntry(manifest, filename, "Name", filename);
        assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle1");
        assertManifestEntry(manifest, filename, "Bundle-Version", "1.1.0");

        filename = getBundleName("bundle2");

        assertManifestEntry(manifest, filename, "Name", filename);
        assertManifestEntry(manifest, filename, "Bundle-SymbolicName", "testbundles.bundle2");
        assertManifestEntry(manifest, filename, "Bundle-Version", "1.0.0");

        try {
            byte[] buf = new byte[32 * 1024];

            JarEntry entry;
            while ((entry = jis.getNextJarEntry()) != null) {
                if (entry.getName().endsWith("valid-bundle1.jar")) {
                    int read = jis.read(buf);

                    JarInputStream jis2 = new JarInputStream(new ByteArrayInputStream(Arrays.copyOf(buf, read)));
                    Manifest manifest2 = jis2.getManifest();

                    Attributes mainAttributes = manifest2.getMainAttributes();
                    assertEquals("1.1.0", mainAttributes.getValue("Bundle-Version"));
                    assertEquals("bar", mainAttributes.getValue("Foo"));
                   
                    jis2.close();
                }
                jis.closeEntry();
            }
        }
        finally {
View Full Code Here

TOP

Related Classes of java.util.jar.JarInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.