Package java.util.jar

Examples of java.util.jar.JarOutputStream


    public void build(OutputStream output) throws IOException {
        if (skipCompile()) {
            return;
        }
        compile();
        JarOutputStream jar = new JarOutputStream(output);
        try {
            LOG.debug("コンパイル結果をパッケージングします");
            List<ResourceRepository> repos = Lists.create();
            if (classDirectory.exists()) {
                repos.add(new FileRepository(classDirectory));
            }
            boolean exists = drain(
                    jar,
                    repos,
                    fragmentRepositories);
            if (exists == false) {
                LOG.warn("ビルド結果にファイルがひとつも存在しません");
                addDummyEntry(jar);
            }
        } finally {
            try {
                jar.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
View Full Code Here


    public void packageSources(OutputStream output) throws IOException {
        if (skipCompile()) {
            return;
        }
        LOG.debug("生成されたソースプログラムをパッケージングします");
        JarOutputStream jar = new JarOutputStream(output);
        try {
            boolean exists = drain(
                    jar,
                    Collections.singletonList(new FileRepository(sourceDirectory)),
                    Collections.<ResourceRepository>emptyList());
            if (exists == false) {
                LOG.warn("ソースファイルがひとつも存在しません");
                addDummyEntry(jar);
            }
        } finally {
            try {
                jar.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
View Full Code Here

        };
    }

    @Override
    public void build(OutputStream output) throws IOException {
        JarOutputStream jar = new JarOutputStream(output);
        try {
            compile(jar);
        } finally {
            jar.close();
        }
    }
View Full Code Here

        }
    }

    @Override
    public void packageSources(OutputStream output) throws IOException {
        JarOutputStream jar = new JarOutputStream(output);
        try {
            collect(jar);
        } finally {
            jar.close();
        }
    }
View Full Code Here

        // A set of paths already written to the jar
        Set<String> writtenPaths = new HashSet<String>();
       
        // Open the output stream as a jar output stream. Write out the XML
        // information files if they exist.
        JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
        writeManifest(jos);
       
        if (moduleInfo != null) {
            JarEntry entry = new JarEntry("module.xml");
            jos.putNextEntry(entry);
            moduleInfo.encode(jos);
        }
       
        if (moduleRequires != null) {
            JarEntry entry = new JarEntry("requires.xml");
            jos.putNextEntry(entry);
            moduleRequires.encode(jos);
        }
       
        if (moduleRepository != null) {
            JarEntry entry = new JarEntry("repository.xml");
            jos.putNextEntry(entry);
            moduleRepository.encode(jos);
        }
       
        // Write out an entry for the art/ directory
        if (moduleArt != null) {
            Iterator<Map.Entry<String, File>> it = moduleArt.entrySet().iterator();
            while (it.hasNext() == true) {
                Map.Entry<String, File> mapEntry = it.next();
                String path = "art/" + mapEntry.getKey();
                writeDirectory(jos, path, writtenPaths);
                JarEntry entry = new JarEntry(fixPath(path));
                jos.putNextEntry(entry);
                FileUtils.copyFile(new FileInputStream(mapEntry.getValue()), jos);
            }
        }

        if (directories!=null) {
            for(File dir : directories) {
                writeDirectoryTree(jos, dir, dir.getParent().toString().length()+1, writtenPaths);
            }
        }

        jos.close();
    }
View Full Code Here

     * @param output
     */
    public JARWriter(File output) {

        try {
            this.jarOutputStream = new JarOutputStream(new FileOutputStream(output));
           
            ZipEntry zipEntry = new ZipEntry("myxxx/test.txt");
            zipEntry.setComment("my Comment");
           
            this.jarOutputStream.putNextEntry(zipEntry);
View Full Code Here

      throws IOException {
    JarFile jarFile = new JarFile(sourceJarFileName);
    ArrayList<JarEntry> entries = Collections.list(jarFile.entries());

    OutputStream os = new FileOutputStream(destJarFileName);
    JarOutputStream out = new JarOutputStream(os);

    int n = 0;
    for (JarEntry entry : entries) {
      if (entry.getName().endsWith(".class"))
        n++;
    }
    displayStartMessage(n);

    for (JarEntry entry : entries) {
      String name = entry.getName();
      InputStream dataStream = null;
      if (name.endsWith(".class")) {
        // weave class
        InputStream is = jarFile.getInputStream(entry);
        ByteArrayOutputStream classStream = new ByteArrayOutputStream();
        if (weave(is, name, classStream)) {
          // class file was modified
          weavedClassCount++;

          dataStream = new ByteArrayInputStream(classStream
              .toByteArray());

          // create new entry
          String newName;
          if (originalClassName != className) {
            String unqualifiedName;
            int index = className.lastIndexOf('/');
            if (index == -1)
              unqualifiedName = className;
            else
              unqualifiedName = className.substring(index + 1,
                  className.length());

            index = name.lastIndexOf('/');
            if (index == -1)
              newName = unqualifiedName + ".class";
            else
              newName = name.substring(0, index + 1)
                  + unqualifiedName + ".class";

          } else {
            newName = name;
          }
          entry = new JarEntry(newName);
          recordFileForVerifier(newName);
        }
      }

      if (dataStream == null) {
        // not a class file or class wasn't no
        dataStream = jarFile.getInputStream(entry);
      }
      // writing entry
      out.putNextEntry(entry);

      // writing data
      int len;
      final byte[] buf = new byte[1024];
      while ((len = dataStream.read(buf)) >= 0) {
        out.write(buf, 0, len);
      }
    }
    out.close();

    displayEndMessage();

    if (verifier != null) {
      verifier.verifyJarFile(destJarFileName);
View Full Code Here

      throws IOException {
    JarFile jarFile = new JarFile(sourceJarFileName);
    ArrayList<JarEntry> entries = Collections.list(jarFile.entries());

    OutputStream os = new FileOutputStream(destJarFileName);
    JarOutputStream out = new JarOutputStream(os);

    int n = 0;
    for (JarEntry entry : entries) {
      if (entry.getName().endsWith(".class")) {
        n++;
      }
    }
    displayStartMessage(n);

    for (JarEntry entry : entries) {
      String name = entry.getName();
      InputStream dataStream = null;
      if (name.endsWith(".class")) {
        // weave class
        InputStream is = jarFile.getInputStream(entry);
        ByteArrayOutputStream classStream = new ByteArrayOutputStream();
        if (weave(is, name, classStream)) {
          // class file was modified
          weavedClassCount++;

          dataStream = new ByteArrayInputStream(classStream
              .toByteArray());

          // create new entry
          entry = new JarEntry(name);
          recordFileForVerifier(name);
        }
      }

      if (dataStream == null) {
        // not a class file or class wasn't no
        dataStream = jarFile.getInputStream(entry);
      }
      // writing entry
      out.putNextEntry(entry);

      // writing data
      int len;
      final byte[] buf = new byte[1024];
      while ((len = dataStream.read(buf)) >= 0) {
        out.write(buf, 0, len);
      }
    }
    out.close();

    displayEndMessage();

    if (verifier != null) {
      verifier.verifyJarFile(destJarFileName);
View Full Code Here

public static void appendJar( String  fromJar, String toJar)   throws IOException {
   JarInputStream in = new JarInputStream(new FileInputStream(fromJar)); // oldJarName is the JAR that contains all the files we want to keep
   String toJarComp = toJar.substring(toJar.lastIndexOf(File.separatorChar)+1, toJar.length());

   String tempJarName = fromJar.replaceAll(".jar", "")+toJarComp;
   JarOutputStream out = new JarOutputStream(new FileOutputStream(tempJarName)); // this is your "out" variable

// copy the files from the old JAR to the new, but don't close the new JAR yet
JarEntry inEnt;
while ((inEnt = in.getNextJarEntry()) != null) {
  JarEntry outEnt = new JarEntry(inEnt); // copy size, modification time etc.
  byte[] data = new byte[(int)inEnt.getSize()];
  in.read(data); // read data for this old entry
  in.closeEntry();
  out.putNextEntry(outEnt);
  out.write(data); // copy it to the new entry
  out.closeEntry();
}
in.close();

in = new JarInputStream(new FileInputStream(toJar));
// copy the files from the old JAR to the new, but don't close the new JAR yet
while ((inEnt = in.getNextJarEntry()) != null) {
  JarEntry outEnt = new JarEntry(inEnt); // copy size, modification time etc.
  byte[] data = new byte[(int)inEnt.getSize()];
  in.read(data); // read data for this old entry
  in.closeEntry();
  out.putNextEntry(outEnt);
  out.write(data); // copy it to the new entry
  out.closeEntry();
}
// and *now* we close the new JAR file.
out.close();
in.close();

// We then delete the old JAR file...
//File origFile = new File(fromJar);
//boolean status = origFile.delete();
View Full Code Here

      throws IOException {
    JarFile jarFile = new JarFile(sourceJarFileName);
    ArrayList<JarEntry> entries = Collections.list(jarFile.entries());

    OutputStream os = new FileOutputStream(destJarFileName);
    JarOutputStream out = new JarOutputStream(os);

    int n = 0;
    for (JarEntry entry : entries) {
      if (entry.getName().endsWith(".class"))
        n++;
    }
    displayStartMessage(n);

    for (JarEntry entry : entries) {
      String name = entry.getName();
      InputStream dataStream = null;
      if (name.endsWith(".class")) {
        // weave class
        InputStream is = jarFile.getInputStream(entry);
        ByteArrayOutputStream classStream = new ByteArrayOutputStream();
        if (weave(is, name, classStream)) {
          // class file was modified
          weavedClassCount++;

          dataStream = new ByteArrayInputStream(classStream
              .toByteArray());

          // create new entry
          entry = new JarEntry(name);
          recordFileForVerifier(name);
        }
      }

      if (dataStream == null) {
        // not a class file or class wasn't no
        dataStream = jarFile.getInputStream(entry);
      }
      // writing entry
      out.putNextEntry(entry);

      // writing data
      int len;
      final byte[] buf = new byte[1024];
      while ((len = dataStream.read(buf)) >= 0) {
        out.write(buf, 0, len);
      }
    }
    out.close();

    displayEndMessage();

    if (verifier != null) {
      verifier.verifyJarFile(destJarFileName);
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.