org.codehaus.cargo.module
Class DefaultJarArchive

java.lang.Object
  extended by org.codehaus.cargo.module.DefaultJarArchive
All Implemented Interfaces:
JarArchive
Direct Known Subclasses:
DefaultEarArchive, DefaultEjbArchive, DefaultWarArchive

public class DefaultJarArchive
extends java.lang.Object
implements JarArchive

Provide convenient methods to read information from a Jar archive.

Version:
$Id: DefaultJarArchive.java 1705 2008-09-02 13:14:55Z adriana $

Constructor Summary
DefaultJarArchive(java.io.InputStream inputStream)
          Constructor.
DefaultJarArchive(java.lang.String file)
          Constructor.
 
Method Summary
 boolean containsClass(java.lang.String className)
          Returns whether a class of the specified name is contained in the archive.
 void expandToPath(java.lang.String path)
          Expand the archive to the specified directory.
 void expandToPath(java.lang.String path, java.io.FileFilter filter)
          Expand the archive to the specified directory, filtering out files.
 java.lang.String findResource(java.lang.String name)
          Returns the full path of a named resource in the archive.
protected  java.util.jar.JarInputStream getContentAsStream()
          Returns the content of the archive as JarInputStream.
 FileHandler getFileHandler()
           
 java.io.InputStream getResource(java.lang.String path)
          Returns a resource from the archive as input stream.
 java.util.List getResources(java.lang.String path)
          Returns the list of resources in the specified directory in the archive.
 void setFileHandler(FileHandler fileHandler)
           
protected  byte[] streamToByteArray(java.io.InputStream inputStream)
          Read a stream into a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultJarArchive

public DefaultJarArchive(java.lang.String file)
Constructor.

Parameters:
file - The archive file

DefaultJarArchive

public DefaultJarArchive(java.io.InputStream inputStream)
                  throws java.io.IOException
Constructor.

Parameters:
inputStream - The input stream for the archive (it will be closed after the constructor returns)
Throws:
java.io.IOException - If there was a problem reading the WAR
Method Detail

getFileHandler

public FileHandler getFileHandler()
Returns:
the file utility class to use for performing all file I/O.

setFileHandler

public void setFileHandler(FileHandler fileHandler)
Parameters:
fileHandler - the file utility class to use for performing all file I/O.

containsClass

public boolean containsClass(java.lang.String className)
                      throws java.io.IOException
Returns whether a class of the specified name is contained in the archive.

Specified by:
containsClass in interface JarArchive
Parameters:
className - The name of the class to search for
Returns:
Whether the class was found
Throws:
java.io.IOException - If an I/O error occurred reading the archive
See Also:
JarArchive.containsClass(String)

findResource

public final java.lang.String findResource(java.lang.String name)
                                    throws java.io.IOException
Returns the full path of a named resource in the archive.

Specified by:
findResource in interface JarArchive
Parameters:
name - The name of the resource
Returns:
The full path to the resource inside the archive
Throws:
java.io.IOException - If an I/O error occurred reading the archive
See Also:
JarArchive.findResource(String)

getResource

public final java.io.InputStream getResource(java.lang.String path)
                                      throws java.io.IOException
Returns a resource from the archive as input stream.

Specified by:
getResource in interface JarArchive
Parameters:
path - The path to the resource in the archive
Returns:
An input stream containing the specified resource, or null if the resource was not found in the JAR
Throws:
java.io.IOException - If an I/O error occurs
See Also:
JarArchive.getResource(String)

getResources

public final java.util.List getResources(java.lang.String path)
                                  throws java.io.IOException
Returns the list of resources in the specified directory in the archive.

Specified by:
getResources in interface JarArchive
Parameters:
path - The directory
Returns:
The list of resources
Throws:
java.io.IOException - If an I/O error occurs
See Also:
JarArchive.getResources(String)

getContentAsStream

protected final java.util.jar.JarInputStream getContentAsStream()
                                                         throws java.io.IOException
Returns the content of the archive as JarInputStream.

Returns:
The input stream
Throws:
java.io.IOException - If an exception occurred reading the archive

expandToPath

public void expandToPath(java.lang.String path)
                  throws java.io.IOException
Expand the archive to the specified directory.

Specified by:
expandToPath in interface JarArchive
Parameters:
path - The path to expand to
Throws:
java.io.IOException - If an I/O error occurs
See Also:
JarArchive.expandToPath(String)

expandToPath

public void expandToPath(java.lang.String path,
                         java.io.FileFilter filter)
                  throws java.io.IOException
Expand the archive to the specified directory, filtering out files.

Specified by:
expandToPath in interface JarArchive
Parameters:
path - The path to expand to
filter - The filter to use
Throws:
java.io.IOException - If an I/O error occurs
See Also:
JarArchive.expandToPath(String, FileFilter)

streamToByteArray

protected byte[] streamToByteArray(java.io.InputStream inputStream)
                            throws java.io.IOException
Read a stream into a byte array.

Parameters:
inputStream - the input stream
Returns:
the byte array
Throws:
java.io.IOException - if an IO Exception


Copyright © 2004-2011 Codehaus. All Rights Reserved.