FileDocCategorySizeDatePackage
JarUtils.javaAPI DocJBoss 4.2.13194Fri Jul 13 20:52:34 BST 2007org.jboss.deployment.spi

JarUtils

public class JarUtils extends Object
A collection of jar utilities
author
thomas.diesler@jboss.org
version
$Revision: 57190 $

Fields Summary
private static final Logger
log
Constructors Summary
Methods Summary
public static java.lang.String[]addJar(java.util.jar.JarOutputStream outputStream, java.lang.String prefix, java.io.File jar)
Add jar contents to the deployment archive under the given prefix


                  
             
   
      log.trace("addJar: " + jar);
      ArrayList tmp = new ArrayList();
      FileInputStream fis = new FileInputStream(jar);
      JarInputStream jis = new JarInputStream(fis);
      JarEntry entry = jis.getNextJarEntry();
      while (entry != null)
      {
         if (entry.isDirectory() == false)
         {
            String entryName = prefix + entry.getName();
            tmp.add(entryName);
            addJarEntry(outputStream, entryName, jis);
         }
         entry = jis.getNextJarEntry();
      }
      jis.close();
      String[] names = new String[tmp.size()];
      tmp.toArray(names);
      return names;
   
public static voidaddJarEntry(java.util.jar.JarOutputStream outputStream, java.lang.String entryName, java.io.InputStream inputStream)
Add a jar entry to the deployment archive

      log.trace("addJarEntry: " + entryName);
      outputStream.putNextEntry(new JarEntry(entryName));
      copyStream(outputStream, inputStream);
   
public static voidcopyStream(java.io.OutputStream outputStream, java.io.InputStream inputStream)
Copies the input stream to the output stream

      byte[] bytes = new byte[4096];
      int read = inputStream.read(bytes, 0, 4096);
      while (read > 0)
      {
         outputStream.write(bytes, 0, read);
         read = inputStream.read(bytes, 0, 4096);
      }