Package org.codehaus.cargo.module
Class DefaultJarArchive
- java.lang.Object
-
- org.codehaus.cargo.module.DefaultJarArchive
-
- All Implemented Interfaces:
JarArchive
- Direct Known Subclasses:
DefaultEarArchive,DefaultEjbArchive,DefaultWarArchive
public class DefaultJarArchive extends Object implements JarArchive
Provide convenient methods to read information from a Jar archive.
-
-
Constructor Summary
Constructors Constructor Description DefaultJarArchive(InputStream inputStream)Constructor.DefaultJarArchive(String file)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsClass(String className)Returns whether a class of the specified name is contained in the archive.voidexpandToPath(String path)Expand the archive to the specified directory.StringfindResource(String name)Returns the full path of a named resource in the archive.protected JarInputStreamgetContentAsStream()Returns the content of the archive asJarInputStream.FileHandlergetFileHandler()InputStreamgetResource(String path)Returns a resource from the archive as input stream.List<String>getResources(String path)Returns the list of resources in the specified directory in the archive.voidsetFileHandler(FileHandler fileHandler)protected byte[]streamToByteArray(InputStream inputStream)Read a stream into a byte array.
-
-
-
Constructor Detail
-
DefaultJarArchive
public DefaultJarArchive(String file)
Constructor.- Parameters:
file- The archive file
-
DefaultJarArchive
public DefaultJarArchive(InputStream inputStream) throws IOException
Constructor.- Parameters:
inputStream- The input stream for the archive (it will be closed after the constructor returns)- Throws:
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(String className) throws IOException
Returns whether a class of the specified name is contained in the archive.- Specified by:
containsClassin interfaceJarArchive- Parameters:
className- The name of the class to search for- Returns:
- Whether the class was found
- Throws:
IOException- If an I/O error occurred reading the archive
-
findResource
public String findResource(String name) throws IOException
Returns the full path of a named resource in the archive.- Specified by:
findResourcein interfaceJarArchive- Parameters:
name- The name of the resource- Returns:
- The full path to the resource inside the archive
- Throws:
IOException- If an I/O error occurred reading the archive
-
getResource
public InputStream getResource(String path) throws IOException
Returns a resource from the archive as input stream.- Specified by:
getResourcein interfaceJarArchive- Parameters:
path- The path to the resource in the archive- Returns:
- An input stream containing the specified resource, or
nullif the resource was not found in the JAR - Throws:
IOException- If an I/O error occurs
-
getResources
public List<String> getResources(String path) throws IOException
Returns the list of resources in the specified directory in the archive.- Specified by:
getResourcesin interfaceJarArchive- Parameters:
path- The directory- Returns:
- The list of resources
- Throws:
IOException- If an I/O error occurs
-
getContentAsStream
protected final JarInputStream getContentAsStream() throws IOException
Returns the content of the archive asJarInputStream.- Returns:
- The input stream
- Throws:
IOException- If an exception occurred reading the archive
-
expandToPath
public void expandToPath(String path) throws IOException
Expand the archive to the specified directory.- Specified by:
expandToPathin interfaceJarArchive- Parameters:
path- The path to expand to- Throws:
IOException- If an I/O error occurs
-
streamToByteArray
protected byte[] streamToByteArray(InputStream inputStream) throws IOException
Read a stream into a byte array.- Parameters:
inputStream- the input stream- Returns:
- the byte array
- Throws:
IOException- if an IO Exception
-
-