org.milyn.archive
Class Archive

java.lang.Object
  extended by org.milyn.archive.Archive

public class Archive
extends Object

Java Archive.

Author:
tom.fennelly@gmail.com

Constructor Summary
Archive()
          Public constructor.
Archive(String archiveName)
          Public constructor.
Archive(String archiveName, ZipInputStream archiveStream)
          Public constructor.
Archive(ZipInputStream archiveStream)
          Public constructor.
 
Method Summary
 Archive addClasspathResourceEntry(String path, String resource)
          Add the specified classpath resource as an entry in the deployment.
 Archive addEntries(ZipInputStream zipStream)
          Add the entries from the supplied ZipInputStream to this archive instance.
 Archive addEntry(Class<?> clazz)
          Add the supplied class as an entry in the deployment.
 Archive addEntry(String path)
          Add an "empty" entry in the deployment.
 Archive addEntry(String path, byte[] data)
          Add the supplied data as an entry in the deployment.
 Archive addEntry(String path, InputStream data)
          Add the supplied data as an entry in the deployment.
 Archive addEntry(String path, String data)
          Add the supplied character data as an entry in the deployment.
 boolean contains(String path)
           
 String getArchiveName()
          Get the name of the deployment associated with this archive.
 Map<String,File> getEntries()
          Get the archive entries.
 File getEntry(String resName)
          Get an Archive entry file.
 byte[] getEntryBytes(String resName)
          Get an Archive entries bytes.
 String getEntryName(int index)
          Get the name of the entry at the specified index in the archive.
 URL getEntryURL(String resName)
          Get an Archive entry resource URL.
 byte[] getEntryValue(int index)
          Get the value of the entry at the specified index in the archive.
 Archive merge(Archive archive)
           
 Archive removeEntry(String path)
          Remove the archive entry at the specified path.
 void toFile(File file)
          Create an archive in the specified File containing entries for the data contained in the streams supplied entries arg.
 void toFileSystem(File outputFolder)
          Output the entries to the specified output folder on the file system.
 ZipInputStream toInputStream()
          Create a ZipInputStream for the entries defined in this archive.
 void toOutputStream(ZipOutputStream archiveStream)
          Create an archive of the specified name and containing entries for the data contained in the streams supplied entries arg.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Archive

public Archive()
Public constructor.


Archive

public Archive(String archiveName)
Public constructor.

Parameters:
archiveName - The archive name of the deployment.

Archive

public Archive(ZipInputStream archiveStream)
        throws IOException
Public constructor.

Parameters:
archiveStream - Archive stream containing initial archive entries.
Throws:
IOException - Error reading from zip stream.

Archive

public Archive(String archiveName,
               ZipInputStream archiveStream)
        throws IOException
Public constructor.

Parameters:
archiveName - The archive name of the deployment.
archiveStream - Archive stream containing initial archive entries.
Throws:
IOException - Error reading from zip stream.
Method Detail

getArchiveName

public String getArchiveName()
Get the name of the deployment associated with this archive.

Returns:
The name of the deployment.

addEntry

public Archive addEntry(String path,
                        InputStream data)
                 throws IOException
Add the supplied data as an entry in the deployment.

Parameters:
path - The target path of the entry when added to the archive.
data - The data.
Returns:
This archive instance.
Throws:
IOException - Error reading from data stream.

addEntry

public Archive addEntry(Class<?> clazz)
                 throws IOException
Add the supplied class as an entry in the deployment.

Parameters:
clazz - The class to be added.
Returns:
This archive instance.
Throws:
IOException - Failed to read class from classpath.

addEntry

public Archive addEntry(String path,
                        byte[] data)
Add the supplied data as an entry in the deployment.

Parameters:
path - The target path of the entry when added to the archive.
data - The data. Pass null to create a directory.
Returns:
This archive instance.

addEntry

public Archive addEntry(String path)
Add an "empty" entry in the deployment.

Equivalent to adding an empty folder.

Parameters:
path - The target path of the entry when added to the archive.
Returns:
This archive instance.

addClasspathResourceEntry

public Archive addClasspathResourceEntry(String path,
                                         String resource)
                                  throws IOException
Add the specified classpath resource as an entry in the deployment.

Parameters:
path - The target path of the entry when added to the archive.
resource - The classpath resource.
Returns:
This archive instance.
Throws:
IOException - Failed to read resource from classpath.

addEntry

public Archive addEntry(String path,
                        String data)
Add the supplied character data as an entry in the deployment.

Parameters:
path - The target path of the entry when added to the archive.
data - The data.
Returns:
This archive instance.

addEntries

public Archive addEntries(ZipInputStream zipStream)
                   throws IOException
Add the entries from the supplied ZipInputStream to this archive instance.

Parameters:
zipStream - The zip stream.
Returns:
This archive instance.
Throws:
IOException - Error reading zip stream.

removeEntry

public Archive removeEntry(String path)
Remove the archive entry at the specified path.

Parameters:
path - The target path of the entry to be removed from the archive.
Returns:
This archive instance.

getEntries

public Map<String,File> getEntries()
Get the archive entries.

The returned map entries are ordered in line with the order in which they were added to the archive.

Returns:
An unmodifiable Map of the archive entries.

getEntryName

public String getEntryName(int index)
Get the name of the entry at the specified index in the archive.

Parameters:
index - The index.
Returns:
The entry name at that index.

getEntryValue

public byte[] getEntryValue(int index)
Get the value of the entry at the specified index in the archive.

Parameters:
index - The index.
Returns:
The entry value at that index.

getEntryBytes

public byte[] getEntryBytes(String resName)
Get an Archive entries bytes.

Parameters:
resName - Entry resource name.
Returns:
The bytes, or null if the entry is not in the Archive.

getEntry

public File getEntry(String resName)
Get an Archive entry file.

Parameters:
resName - Entry resource name.
Returns:
The entry File, or null if the entry is not in the Archive.

getEntryURL

public URL getEntryURL(String resName)
Get an Archive entry resource URL.

Parameters:
resName - Entry resource name.
Returns:
The entry resource URL, or null if the entry is not in the Archive.

toOutputStream

public void toOutputStream(ZipOutputStream archiveStream)
                    throws IOException
Create an archive of the specified name and containing entries for the data contained in the streams supplied entries arg. specifying the entry name and the value is a InputStream containing the entry data.

Parameters:
archiveStream - The archive output stream.
Throws:
IOException - Write failure.

toFile

public void toFile(File file)
            throws IOException
Create an archive in the specified File containing entries for the data contained in the streams supplied entries arg. specifying the entry name and the value is a InputStream containing the entry data.

Parameters:
file - The archive file.
Throws:
IOException - Write failure.

toFileSystem

public void toFileSystem(File outputFolder)
                  throws IOException
Output the entries to the specified output folder on the file system.

Parameters:
outputFolder - The target output folder.
Throws:
IOException - Write failure.

toInputStream

public ZipInputStream toInputStream()
                             throws IOException
Create a ZipInputStream for the entries defined in this archive.

Returns:
The ZipInputStream for the entries in this archive.
Throws:
IOException - Failed to create stream.

merge

public Archive merge(Archive archive)

contains

public boolean contains(String path)


Copyright © 2018. All rights reserved.