net.sf.exorcist.core.memory
Class MemoryContentState

java.lang.Object
  extended by net.sf.exorcist.core.memory.MemoryContentState
All Implemented Interfaces:
java.io.Serializable, ContentState

public class MemoryContentState
extends java.lang.Object
implements ContentState, java.io.Serializable

See Also:
Serialized Form

Constructor Summary
MemoryContentState()
           
 
Method Summary
 java.lang.String addAttachment(java.io.InputStream data)
          Adds a binary attachment.
 java.io.InputStream getAttachment(java.lang.String hash)
          Returns the attachment with the given hash code.
 java.util.Collection getAttachmentHashes()
          Returns the hashe codes of all the attachments.
 java.io.InputStream getContent()
          Returns the serialized XML document that represents the content state snapshot.
 void removeAttachment(java.lang.String hash)
          Removes the attachment with the given hash code.
 void setContent(java.io.InputStream content)
          Sets the serialized XML document that represents the content state snapshot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryContentState

public MemoryContentState()
Method Detail

getContent

public java.io.InputStream getContent()
Description copied from interface: ContentState
Returns the serialized XML document that represents the content state snapshot.

The returned input stream should always contain a well-formed XML document although the implementation class might not strictly enforce this. Possible XML parsing exceptions can thus be treated as fatal errors.

The returned input stream belongs to the caller and should be closed when it is no longer used.

Specified by:
getContent in interface ContentState
Returns:
content XML

setContent

public void setContent(java.io.InputStream content)
                throws java.io.IOException
Description copied from interface: ContentState
Sets the serialized XML document that represents the content state snapshot.

The given input stream should contain a well-formed XML document. The implementation class is not required to strictly enforce this requirement to avoid unnecessary processing, but failure to produce a well-formed XML document should still be considered a fatal error.

The given input stream is consumed until it ends or an exception occurs, but it is not closed. It is the responsibility of the caller to properly close the stream.

Specified by:
setContent in interface ContentState
Parameters:
content - content XML stream
Throws:
java.io.IOException - if the stream can not be read

addAttachment

public java.lang.String addAttachment(java.io.InputStream data)
                               throws java.io.IOException
Description copied from interface: ContentState
Adds a binary attachment. The attachment is read from the given input stream and the SHA-1 hash of the received data is computed. The binary data is saved as a part of the content state and the identifying hash code is returned as a hex-encoded string.

The given input stream is consumed until it ends or an exception occurs, but it is not closed. It is the responsibility of the caller to properly close the stream.

Specified by:
addAttachment in interface ContentState
Parameters:
data - input stream containing the attachment
Returns:
the SHA-1 hash of the attachment
Throws:
java.io.IOException - if the attachment stream could not be read

getAttachmentHashes

public java.util.Collection getAttachmentHashes()
Description copied from interface: ContentState
Returns the hashe codes of all the attachments.

Specified by:
getAttachmentHashes in interface ContentState
Returns:
SHA-1 hashes of all the attachments

getAttachment

public java.io.InputStream getAttachment(java.lang.String hash)
                                  throws java.lang.IllegalArgumentException
Description copied from interface: ContentState
Returns the attachment with the given hash code. The binary contents of the identified attachment is returned as an input stream. The caller should make sure that the returned input stream is properly closed when it is no longer used.

Specified by:
getAttachment in interface ContentState
Parameters:
hash - SHA-1 hash of the attachment
Returns:
input stream containing the attached data
Throws:
java.lang.IllegalArgumentException - if an attachment with the given hash code does not exist

removeAttachment

public void removeAttachment(java.lang.String hash)
                      throws java.lang.IllegalArgumentException
Description copied from interface: ContentState
Removes the attachment with the given hash code.

Specified by:
removeAttachment in interface ContentState
Parameters:
hash - SHA-1 hash of the attachment
Throws:
java.lang.IllegalArgumentException - if an attachment with the given hash code does not exist


Copyright © 2005 The Exorcist Team @ SourceForge. All Rights Reserved.