org.pentaho.reporting.libraries.repository.stream
Class StreamContentItem

java.lang.Object
  extended by org.pentaho.reporting.libraries.repository.stream.StreamContentItem
All Implemented Interfaces:
ContentEntity, ContentItem

public class StreamContentItem
extends java.lang.Object
implements ContentItem

A stream-content item that wraps around the input and output streams given in the repository. Depending on which stream are given, this item reports itself as read or writable.

Author:
Thomas Morgner

Constructor Summary
StreamContentItem(java.lang.String name, ContentLocation parent, WrappedInputStream inputStream, WrappedOutputStream outputStream)
          Creates a new stream-content item.
 
Method Summary
 boolean delete()
          Stream-repositories do not support the deletion of entries.
 java.lang.Object getAttribute(java.lang.String domain, java.lang.String key)
          Stream-Repositories do not support attributes.
 java.lang.Object getContentId()
          Returns a unique identifier.
 java.io.InputStream getInputStream()
          Tries to open and return a input stream for reading from the content item.
 java.lang.String getMimeType()
          Returns the mime type for the content entity.
 java.lang.String getName()
          Returns the name of the entry.
 java.io.OutputStream getOutputStream()
          Tries to open and return a output stream for writing into the content item.
 ContentLocation getParent()
          Returns a reference to the parent location.
 Repository getRepository()
          Returns the current repository, to which tis entity belongs.
 boolean isReadable()
          Checks, whether the content item is readable.
 boolean isWriteable()
          Checks, whether the content item is writable.
 boolean setAttribute(java.lang.String domain, java.lang.String key, java.lang.Object value)
          Stream-Repositories do not support attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamContentItem

public StreamContentItem(java.lang.String name,
                         ContentLocation parent,
                         WrappedInputStream inputStream,
                         WrappedOutputStream outputStream)
Creates a new stream-content item. The item will have the given name and parent and will wrap around the provided streams.

Parameters:
name - the name of the content item.
parent - the parent location.
inputStream - the (optional) input stream.
outputStream - the (optional) output stream.
Method Detail

isReadable

public boolean isReadable()
Checks, whether the content item is readable. A content item that is not readable will never return a valid inputstream and any call to getInputStream is bound to fail.

Specified by:
isReadable in interface ContentItem
Returns:
true, if the content item is readable, false otherwise.

isWriteable

public boolean isWriteable()
Checks, whether the content item is writable. A content item that is not writable will never return a valid outputstream and any call to getOutputStream is bound to fail.

Specified by:
isWriteable in interface ContentItem
Returns:
true, if the content item is writeable, false otherwise.

getMimeType

public java.lang.String getMimeType()
                             throws ContentIOException
Returns the mime type for the content entity. If the repository does not store mimetypes, this call usually uses the repositories MimeRegistry to resolve the mimetype.

Specified by:
getMimeType in interface ContentItem
Returns:
the mime type.
Throws:
ContentIOException - if an error occured.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws ContentIOException,
                                            java.io.IOException
Tries to open and return a output stream for writing into the content item. This call will fail if the item is not writeable. Whether opening multiple output streams at the same time is possible is implementation dependent, but it is generally not recommended to try this.

Having both an input and output stream open at the same time is not guaranteed to work. Generally if you need to append data, first open the inputstream and copy the content to a temporary location and then write the content along with the appended content to the new output stream.

Specified by:
getOutputStream in interface ContentItem
Returns:
the output stream for writing the item.
Throws:
ContentIOException - if an repository related error prevents the creation of the output stream.
java.io.IOException - if an IO error occurs.

getInputStream

public java.io.InputStream getInputStream()
                                   throws ContentIOException,
                                          java.io.IOException
Tries to open and return a input stream for reading from the content item. This call will fail if the item is not readable. Whether opening multiple input streams at the same time is possible is implementation dependent.

Having both an input and output stream open at the same time is not guaranteed to work. Generally if you need to append data, first open the inputstream and copy the content to a temporary location and then write the content along with the appended content to the new output stream.

Specified by:
getInputStream in interface ContentItem
Returns:
the input stream for reading from the item.
Throws:
ContentIOException - if an repository related error prevents the creation of the input stream.
java.io.IOException - if an IO error occurs.

getName

public java.lang.String getName()
Returns the name of the entry.

Specified by:
getName in interface ContentEntity
Returns:
the name, never null.

getContentId

public java.lang.Object getContentId()
Returns a unique identifier. This can be canonical filename or a database key. It must be guaranteed that within the same repository the key will be unique.

Specified by:
getContentId in interface ContentEntity
Returns:
the unique content ID.

getAttribute

public java.lang.Object getAttribute(java.lang.String domain,
                                     java.lang.String key)
Stream-Repositories do not support attributes.

Specified by:
getAttribute in interface ContentEntity
Parameters:
domain - the attribute domain.
key - the name of the attribute.
Returns:
always null.

setAttribute

public boolean setAttribute(java.lang.String domain,
                            java.lang.String key,
                            java.lang.Object value)
Stream-Repositories do not support attributes.

Specified by:
setAttribute in interface ContentEntity
Parameters:
domain - the attribute domain.
key - the attribute name
value - the new attribute value.
Returns:
always false.

getParent

public ContentLocation getParent()
Returns a reference to the parent location. If this entity represents the root directory, this method will return null.

Specified by:
getParent in interface ContentEntity
Returns:
the parent or null, if this is the root-directory.

getRepository

public Repository getRepository()
Returns the current repository, to which tis entity belongs.

Specified by:
getRepository in interface ContentEntity
Returns:
the repository.

delete

public boolean delete()
Stream-repositories do not support the deletion of entries.

Specified by:
delete in interface ContentEntity
Returns:
always false.