org.alfresco.service.cmr.repository
Interface ContentReader

All Superinterfaces:
ContentAccessor
All Known Subinterfaces:
FileContentReader

public interface ContentReader
extends ContentAccessor

Represents a handle to read specific content. Content may only be accessed once per instance.

Implementations of this interface might be Serializable but client code could should check suitability before attempting to serialize it.

Implementations that are able to provide inter-VM streaming, such as accessing WebDAV, would be Serializable. An accessor that has to access a local file on the server could not provide inter-VM streaming unless it specifically makes remote calls and opens sockets, etc.

See Also:
ContentWriter

Method Summary
 boolean exists()
          Check if the underlying content is present.
 void getContent(java.io.File file)
          Gets content from the repository direct to file
 void getContent(java.io.OutputStream os)
          Gets content from the repository.
 java.io.InputStream getContentInputStream()
          Get a stream to read from the underlying channel
 java.lang.String getContentString()
          Gets content from the repository direct to String.
 java.lang.String getContentString(int length)
          Gets content from the repository direct to String, but limiting the string size to a given number of characters.
 java.nio.channels.FileChannel getFileChannel()
          Provides read-only, random-access to the underlying content.
 long getLastModified()
          Gets the time of the last modification of the underlying content.
 java.nio.channels.ReadableByteChannel getReadableChannel()
          Provides low-level access to the underlying content.
 ContentReader getReader()
          Convenience method to get another reader onto the underlying content.
 boolean isClosed()
          Convenience method to find out if this reader has been closed.
 
Methods inherited from interface org.alfresco.service.cmr.repository.ContentAccessor
addListener, getContentData, getContentUrl, getEncoding, getLocale, getMimetype, getSize, isChannelOpen, setEncoding, setLocale, setMimetype
 

Method Detail

getReader

ContentReader getReader()
                        throws ContentIOException
Convenience method to get another reader onto the underlying content.

Returns:
Returns a reader onto the underlying content
Throws:
ContentIOException

exists

boolean exists()
Check if the underlying content is present.

Returns:
Returns true if there is content at the URL refered to by this reader

getLastModified

long getLastModified()
Gets the time of the last modification of the underlying content.

Returns:
Returns the last modification time using the standard long time, or 0L if the content doesn't exist.
See Also:
System.currentTimeMillis()

isClosed

boolean isClosed()
Convenience method to find out if this reader has been closed. Once closed, the content can no longer be read. This method could be used to wait for a particular read operation to complete, for example.

Returns:
Return true if the content input stream has been used and closed otherwise false.

getReadableChannel

java.nio.channels.ReadableByteChannel getReadableChannel()
                                                         throws ContentIOException
Provides low-level access to the underlying content.

Once the stream is provided to a client it should remain active (subject to any timeouts) until closed by the client.

Returns:
Returns a stream that can be read at will, but must be closed when completed
Throws:
ContentIOException

getFileChannel

java.nio.channels.FileChannel getFileChannel()
                                             throws ContentIOException
Provides read-only, random-access to the underlying content. In general, this method should be considered more expensive than the sequential-access method, ContentReader.getReadableChannel().

Returns:
Returns a random-access channel onto the content
Throws:
ContentIOException
See Also:
ContentReader.getReadableChannel(), RandomAccessFile.getChannel()

getContentInputStream

java.io.InputStream getContentInputStream()
                                          throws ContentIOException
Get a stream to read from the underlying channel

Returns:
Returns an input stream onto the underlying channel
Throws:
ContentIOException
See Also:
ContentReader.getReadableChannel()

getContent

void getContent(java.io.OutputStream os)
                throws ContentIOException
Gets content from the repository.

All resources will be closed automatically.

Care must be taken that the bytes read from the stream are properly decoded according to the encoding property.

Parameters:
os - the stream to which to write the content
Throws:
ContentIOException
See Also:
ContentReader.getReadableChannel()

getContent

void getContent(java.io.File file)
                throws ContentIOException
Gets content from the repository direct to file

All resources will be closed automatically.

Parameters:
file - the file to write the content to - it will be overwritten
Throws:
ContentIOException
See Also:
ContentReader.getContentInputStream()

getContentString

java.lang.String getContentString()
                                  throws ContentIOException
Gets content from the repository direct to String.

If the encoding is known then it will be used otherwise the default system byte[] to String conversion will be used.

All resources will be closed automatically.

WARNING: This should only be used when the size of the content is known in advance.

Returns:
Returns a String representation of the content
Throws:
ContentIOException
See Also:
ContentReader.getContentString(int), ContentReader.getContentInputStream(), String.String(byte[])

getContentString

java.lang.String getContentString(int length)
                                  throws ContentIOException
Gets content from the repository direct to String, but limiting the string size to a given number of characters.

If the encoding is known then it will be used otherwise the default system byte[] to String conversion will be used.

All resources will be closed automatically.

Parameters:
length - the maximum number of characters to retrieve
Returns:
Returns a truncated String representation of the content
Throws:
ContentIOException
java.lang.IllegalArgumentException - if the length is < 0 or > Integer.MAX_VALUE
See Also:
ContentReader.getContentString(), ContentReader.getContentInputStream(), String.String(byte[])


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.