org.glassfish.osgijavaeebase
Class JarHelper

java.lang.Object
  extended by org.glassfish.osgijavaeebase.JarHelper

public class JarHelper
extends Object

A utility class to help reading/writing content of JarFile from/to stream.

Author:
Sanjeeb.Sahoo@Sun.COM

Nested Class Summary
static interface JarHelper.Visitor
           
 
Constructor Summary
JarHelper()
           
 
Method Summary
static void accept(JarInputStream jis, JarHelper.Visitor visitor)
           
static void copy(InputStream in, OutputStream out, ByteBuffer byteBuffer)
          Copies input to output.
static InputStream makeJar(File dir, Runnable action)
          A utility method to make a JarInputStream out of the contents of a directory.
static void write(JarInputStream jis, JarOutputStream jos)
          A utility method to help write content of a Jar input stream to a Jar output stream.
static void write(URLConnection con, OutputStream os, Manifest m)
          A utility method which reads contents from a URLConnection and writes it out a Jar output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarHelper

public JarHelper()
Method Detail

accept

public static void accept(JarInputStream jis,
                          JarHelper.Visitor visitor)
                   throws IOException
Throws:
IOException

write

public static void write(URLConnection con,
                         OutputStream os,
                         Manifest m)
A utility method which reads contents from a URLConnection and writes it out a Jar output stream. It reads everything except manifest from the input. Closing of output stream is caller's responsibility.

Parameters:
con - URLConnection to be used as input
os - Output stream to write to
m - Manifest to be written out - can't be null
Throws:
IOException

write

public static void write(JarInputStream jis,
                         JarOutputStream jos)
                  throws IOException
A utility method to help write content of a Jar input stream to a Jar output stream. It reads everything except manifest from the supplied InputStream. Closing of streams is caller's responsibility.

Parameters:
jis - input stream to read from
jos - output stream to write to
Throws:
IOException

makeJar

public static InputStream makeJar(File dir,
                                  Runnable action)
                           throws IOException
A utility method to make a JarInputStream out of the contents of a directory. It uses a Pipe and a separate thread to write the contents to avoid deadlock. It accepts a Runnable to take action once the spwaned thread has finished writing. It can be used to delete the directory.

Parameters:
dir - Directory which contains the exploded bits
action - A runnable to be called after output has been written
Returns:
a InputStream
Throws:
IOException

copy

public static void copy(InputStream in,
                        OutputStream out,
                        ByteBuffer byteBuffer)
                 throws IOException
Copies input to output. To avoid unnecessary allocation of byte buffers, this method takes a byte buffer as argument. It clears the byte buffer at the end of the operation.

Parameters:
in -
out -
byteBuffer -
Throws:
IOException


Copyright © 2012 GlassFish Community. All Rights Reserved.