org.overlord.sramp.atom.archive
Class SrampArchive

java.lang.Object
  extended by org.overlord.sramp.atom.archive.SrampArchive

public class SrampArchive
extends Object

Models the archive format defined in the S-RAMP Atom Binding document.

Author:
eric.wittmann@redhat.com

Constructor Summary
SrampArchive()
          Creates a new, empty S-RAMP archive.
SrampArchive(File file)
          Creates an S-RAMP archive from an existing archive file.
SrampArchive(InputStream input)
          Creates an S-RAMP archive from an InputStream.
 
Method Summary
 void addEntry(String path, BaseArtifactType metaData, InputStream content)
          Adds an entry to the S-RAMP archive.
 void close()
          The S-RAMP archive should always be closed when the client is done with it.
static void closeQuietly(SrampArchive archive)
          Close the archive quietly (eat any IOException).
 boolean containsEntry(String archivePath)
          Returns true if the s-ramp archive contains an entry at the given path.
 Collection<SrampArchiveEntry> getEntries()
          Gets all of the entries found in this S-RAMP archive.
 SrampArchiveEntry getEntry(String archivePath)
          Gets a single entry in the archive by path.
 InputStream getInputStream(SrampArchiveEntry entry)
          Gets the content InputStream for the given S-RAMP archive entry.
 File pack()
          Packs up the current contents of the S-RAMP archive into a single (.zip) file and returns a reference to it.
 boolean removeEntry(String archivePath)
          Removes the s-ramp archive entry at the given path if it exists.
 void updateEntry(SrampArchiveEntry entry, InputStream content)
          Updates an existing entry in the S-RAMP archive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SrampArchive

public SrampArchive()
             throws SrampArchiveException
Creates a new, empty S-RAMP archive.

Throws:
SrampArchiveException

SrampArchive

public SrampArchive(File file)
             throws SrampArchiveException
Creates an S-RAMP archive from an existing archive file.

Parameters:
file -
Throws:
SrampArchiveException

SrampArchive

public SrampArchive(InputStream input)
             throws SrampArchiveException
Creates an S-RAMP archive from an InputStream. This will consume and close the InputStream, creating a temporary local file that will be used as the basis for the archive input.

Parameters:
input -
Throws:
SrampArchiveException
Method Detail

close

public void close()
           throws IOException
The S-RAMP archive should always be closed when the client is done with it. This will clean up all temporary resources created by the archive.

Throws:
IOException

closeQuietly

public static void closeQuietly(SrampArchive archive)
Close the archive quietly (eat any IOException).

Parameters:
archive -

getEntries

public Collection<SrampArchiveEntry> getEntries()
                                         throws SrampArchiveException
Gets all of the entries found in this S-RAMP archive. It does this by scanning the archive looking for all *.atom files. One entry will be returned for each *.atom file found in the archive (assuming it has associated content and the *.atom file is properly formatted).

Throws:
SrampArchiveException

getInputStream

public InputStream getInputStream(SrampArchiveEntry entry)
                           throws IOException
Gets the content InputStream for the given S-RAMP archive entry.

Parameters:
entry - the s-ramp archive entry
Returns:
an InputStream over the artifact content or null if no content found (meta-data only)
Throws:
IOException

addEntry

public void addEntry(String path,
                     BaseArtifactType metaData,
                     InputStream content)
              throws SrampArchiveException
Adds an entry to the S-RAMP archive. This method will close the content InputStream.

Parameters:
path - the path in the archive (usually just the name of the artifact)
metaData - the artifact meta-data
content - the entry content (or null if a meta-data only entry)
Throws:
SrampArchiveException

updateEntry

public void updateEntry(SrampArchiveEntry entry,
                        InputStream content)
                 throws SrampArchiveException
Updates an existing entry in the S-RAMP archive. This method will close the content InputStream.

Parameters:
entry - the archive entry (or null if just udpating the content)
content - the entry content (or null if just updating meta data)
Throws:
SrampArchiveException

pack

public File pack()
          throws SrampArchiveException
Packs up the current contents of the S-RAMP archive into a single (.zip) file and returns a reference to it. This method is guaranteed to either throw an Exception or return a valid File. It will never throw and leave a temporary file behind.

Throws:
SrampArchiveException

getEntry

public SrampArchiveEntry getEntry(String archivePath)
Gets a single entry in the archive by path.

Parameters:
archivePath - the path of the entry within the archive
Returns:
the archive entry, or null if not found

containsEntry

public boolean containsEntry(String archivePath)
Returns true if the s-ramp archive contains an entry at the given path.

Parameters:
archivePath - path to the entry within the archive
Returns:
true if an entry exists at the path

removeEntry

public boolean removeEntry(String archivePath)
Removes the s-ramp archive entry at the given path if it exists.

Parameters:
archivePath - path to the entry within the archive
Returns:
true if an entry existed and was removed


Copyright © 2011-2013 JBoss, a division of Red Hat. All Rights Reserved.