Package java.util.jar

Examples of java.util.jar.JarOutputStream


    }

    private void createJar(Manifest man, boolean includeIndex) throws IOException
    {
        FileOutputStream fos = new FileOutputStream(m_jarFile);
        JarOutputStream jos;

        if (man == null || includeIndex)
        {
            jos = new JarOutputStream(fos);
        }
        else
        {
            jos = new JarOutputStream(fos, man);
        }

        if (includeIndex)
        {
            // Write the INDEX.LIST file as first entry...
            jos.putNextEntry(new ZipEntry(INDEX_NAME));
            jos.write(("JarIndex-Version: 1.0\n\n" + m_jarFile.getName() + "\n").getBytes());
            jos.closeEntry();

            if (man != null)
            {
                jos.putNextEntry(new ZipEntry(MANIFEST_NAME));
                man.write(jos);
                jos.closeEntry();
            }
        }

        try
        {
            appendFiles(jos, 5);
        }
        finally
        {
            jos.close();
        }
    }
View Full Code Here


    public InputStream buildJar(final IFolder sourceDir) throws CoreException {

        ByteArrayOutputStream store = new ByteArrayOutputStream();

        JarOutputStream zos = null;
        InputStream manifestInput = null;
        try {
            IResource manifestResource = sourceDir.findMember(JarFile.MANIFEST_NAME);
            if (manifestResource == null || manifestResource.getType() != IResource.FILE) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No file named "
                        + JarFile.MANIFEST_NAME + " found under " + sourceDir));
            }

            manifestInput = ((IFile) manifestResource).getContents();
           
            Manifest manifest = new Manifest(manifestInput);

            zos = new JarOutputStream(store);
            zos.setLevel(Deflater.NO_COMPRESSION);
            // manifest first
            final ZipEntry anEntry = new ZipEntry(JarFile.MANIFEST_NAME);
            zos.putNextEntry(anEntry);
            manifest.write(zos);
            zos.closeEntry();
            zipDir(sourceDir, zos, "");
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
        } finally {
            IOUtils.closeQuietly(zos);
View Full Code Here

 
  private JarOutputStream jo;

  public JarClassRepo(File jarFile) throws IOException {
    FileOutputStream fo = new FileOutputStream(jarFile);
    jo = new JarOutputStream(fo);
    jo.setLevel(ZipOutputStream.STORED);
  }
View Full Code Here

    public static void run(File from, File to, JarProcessor proc, boolean ignoreDuplicates) throws IOException {
        byte[] buf = new byte[0x2000];

        JarFile in = new JarFile(from);
        final File tmpTo = File.createTempFile("jarjar", ".jar");
        JarOutputStream out = new JarOutputStream(new FileOutputStream(tmpTo));
        Set<String> entries = new HashSet<String>();
        try {
            EntryStruct struct = new EntryStruct();
            Enumeration<JarEntry> e = in.entries();
            while (e.hasMoreElements()) {
                JarEntry entry = e.nextElement();
                struct.name = entry.getName();
                struct.time = entry.getTime();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IoUtil.pipe(in.getInputStream(entry), baos, buf);
                struct.data = baos.toByteArray();
                if (proc.process(struct)) {
                    if (entries.add(struct.name)) {
                        entry = new JarEntry(struct.name);
                        entry.setTime(struct.time);
                        entry.setCompressedSize(-1);
                        out.putNextEntry(entry);
                        out.write(struct.data);
                    } else if (struct.name.endsWith("/")) {
                        // TODO(chrisn): log
                    } else if (!ignoreDuplicates) {
                        throw new IllegalArgumentException("Duplicate jar entries: " + struct.name);
                    }
                }
            }

        }
        finally {
            try {
                in.close();
            } catch (IOException e) {}
            try {
                out.close();
            } catch (IOException e) {}
        }

         // delete the empty directories
        IoUtil.copyZipWithoutEmptyDirectories(tmpTo, to);
View Full Code Here

        // Create a temporary Jar
        String tmpDir = System.getProperty("java.io.tmpdir");
        File testJarFile = new File(tmpDir + "vaadin." + productName + ".jar");
        testJarFile.deleteOnExit();
        JarOutputStream target = new JarOutputStream(new FileOutputStream(
                testJarFile), testManifest);
        target.close();

        // Add the new jar to our classpath (use reflection)
        URL url = new URL("file://" + testJarFile.getAbsolutePath());
        final Method addURL = URLClassLoader.class.getDeclaredMethod("addURL",
                new Class[] { URL.class });
View Full Code Here

      }
      InputStream is = getResource(classPath);
      OutputStream classOS = new FileOutputStream(new File(dir, classFileName));
      IOUtils.copy(is, classOS);
    }
    JarOutputStream zos = new JarOutputStream(os, new Manifest());
    IOUtils.zipDir(classesDir, "", zos);
    IOUtils.delete(classesDir);
  }
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

            }
        }
    }

    private void writeStream(List<ArtifactData> files, Manifest manifest, OutputStream outputStream) throws Exception {
        JarOutputStream output = null;
        InputStream fis = null;
        try {
            output = new JarOutputStream(outputStream, manifest);
            byte[] buffer = new byte[BUFFER_SIZE];

            Iterator<ArtifactData> filesIter = files.iterator();
            while (filesIter.hasNext()) {
                ArtifactData file = filesIter.next();
                if (file.isMissing()) {
                    // No need to write the 'missing' files...
                    continue;
                }

                output.putNextEntry(new JarEntry(file.getFilename()));

                ResourceFilter filter = file.getFilter();
                if (filter != null) {
                    fis = filter.createInputStream(file.getURL());
                }
                else {
                    fis = file.getURL().openStream();
                }

                try {
                    int bytes = fis.read(buffer);
                    while (bytes != -1) {
                        output.write(buffer, 0, bytes);
                        bytes = fis.read(buffer);
                    }
                }
                finally {
                    fis.close();
                    fis = null;

                    output.closeEntry();
                }
            }
        }
        finally {
            if (fis != null) {
                fis.close();
            }
            if (output != null) {
                output.close();
            }
        }
    }
View Full Code Here

            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

   */
  private void uploadJobJar(JobConf jobConf)
      throws IOException,
      FileNotFoundException {
    File jobJarFile = new File(TEST_ROOT_DIR, "jobjar-on-dfs.jar");
    JarOutputStream jstream =
        new JarOutputStream(new FileOutputStream(jobJarFile));
    ZipEntry ze = new ZipEntry("lib/lib1.jar");
    jstream.putNextEntry(ze);
    jstream.closeEntry();
    ze = new ZipEntry("lib/lib2.jar");
    jstream.putNextEntry(ze);
    jstream.closeEntry();
    jstream.finish();
    jstream.close();
    jobConf.setJar(jobJarFile.toURI().toString());
  }
View Full Code Here

TOP

Related Classes of java.util.jar.JarOutputStream

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.