org.alfresco.repo.content
Class AbstractContentReader

java.lang.Object
  extended by org.alfresco.repo.content.AbstractContentAccessor
      extended by org.alfresco.repo.content.AbstractContentReader
All Implemented Interfaces:
org.alfresco.service.cmr.repository.ContentAccessor, org.alfresco.service.cmr.repository.ContentReader
Direct Known Subclasses:
EmptyContentReader, FileContentReader, HttpAlfrescoContentReader

public abstract class AbstractContentReader
extends AbstractContentAccessor
implements org.alfresco.service.cmr.repository.ContentReader

Implements all the convenience methods of the interface. The only methods that need to be implemented, i.e. provide low-level content access are:


Nested Class Summary
 
Nested classes/interfaces inherited from class org.alfresco.repo.content.AbstractContentAccessor
AbstractContentAccessor.CallbackFileChannel, AbstractContentAccessor.ChannelCloseCallbackAdvise
 
Constructor Summary
protected AbstractContentReader(java.lang.String contentUrl)
           
 
Method Summary
 void addListener(org.alfresco.service.cmr.repository.ContentStreamListener listener)
          Adds the listener after checking that the output stream isn't already in use.
static boolean compareContentReaders(org.alfresco.service.cmr.repository.ContentReader left, org.alfresco.service.cmr.repository.ContentReader right)
          Does a comparison of the binaries associated with two readers.
protected abstract  org.alfresco.service.cmr.repository.ContentReader createReader()
          A factory method for subclasses to implement that will ensure the proper implementation of the ContentReader.getReader() method.
 void getContent(java.io.File file)
           
 void getContent(java.io.OutputStream os)
          Copies the input stream to the given OutputStream
 java.io.InputStream getContentInputStream()
           
 java.lang.String getContentString()
          Makes use of the encoding, if available, to convert bytes to a string.
 java.lang.String getContentString(int length)
           
protected abstract  java.nio.channels.ReadableByteChannel getDirectReadableChannel()
          Provides low-level access to read content from the repository.
 java.nio.channels.FileChannel getFileChannel()
          
 java.nio.channels.ReadableByteChannel getReadableChannel()
           
 org.alfresco.service.cmr.repository.ContentReader getReader()
          Performs checks and copies required reader attributes
 boolean isChannelOpen()
           
 boolean isClosed()
          An automatically created listener sets the flag
 
Methods inherited from class org.alfresco.repo.content.AbstractContentAccessor
channelOpened, finalize, getCallbackFileChannel, getContentData, getContentUrl, getEncoding, getLocale, getMimetype, setContentUrl, setEncoding, setLocale, setMimetype, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.alfresco.service.cmr.repository.ContentReader
exists, getLastModified
 
Methods inherited from interface org.alfresco.service.cmr.repository.ContentAccessor
getContentData, getContentUrl, getEncoding, getLocale, getMimetype, getSize, setEncoding, setLocale, setMimetype
 

Constructor Detail

AbstractContentReader

protected AbstractContentReader(java.lang.String contentUrl)
Parameters:
contentUrl - the content URL - this should be relative to the root of the store and not absolute: to enable moving of the stores
Method Detail

addListener

public void addListener(org.alfresco.service.cmr.repository.ContentStreamListener listener)
Adds the listener after checking that the output stream isn't already in use.

Specified by:
addListener in interface org.alfresco.service.cmr.repository.ContentAccessor

createReader

protected abstract org.alfresco.service.cmr.repository.ContentReader createReader()
                                                                           throws org.alfresco.service.cmr.repository.ContentIOException
A factory method for subclasses to implement that will ensure the proper implementation of the ContentReader.getReader() method.

Only the instance need be constructed. The required mimetype, encoding, etc will be copied across by this class.

Returns:
Returns a reader onto the location referenced by this instance. The instance must always be a new instance.
Throws:
org.alfresco.service.cmr.repository.ContentIOException

getReader

public final org.alfresco.service.cmr.repository.ContentReader getReader()
                                                                  throws org.alfresco.service.cmr.repository.ContentIOException
Performs checks and copies required reader attributes

Specified by:
getReader in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException

isClosed

public final boolean isClosed()
An automatically created listener sets the flag

Specified by:
isClosed in interface org.alfresco.service.cmr.repository.ContentReader

isChannelOpen

public boolean isChannelOpen()
Specified by:
isChannelOpen in interface org.alfresco.service.cmr.repository.ContentAccessor

getDirectReadableChannel

protected abstract java.nio.channels.ReadableByteChannel getDirectReadableChannel()
                                                                           throws org.alfresco.service.cmr.repository.ContentIOException
Provides low-level access to read content from the repository.

This is the only of the content reading methods that needs to be implemented by derived classes. All other content access methods make use of this in their underlying implementations.

Returns:
Returns a channel from which content can be read
Throws:
org.alfresco.service.cmr.repository.ContentIOException - if the channel could not be opened or the underlying content has disappeared

getReadableChannel

public final java.nio.channels.ReadableByteChannel getReadableChannel()
                                                               throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
getReadableChannel in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException
See Also:
AbstractContentReader.getDirectReadableChannel(), AbstractContentReader.getCallbackReadableChannel(ReadableByteChannel, List)

getFileChannel

public java.nio.channels.FileChannel getFileChannel()
                                             throws org.alfresco.service.cmr.repository.ContentIOException

Specified by:
getFileChannel in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException

getContentInputStream

public java.io.InputStream getContentInputStream()
                                          throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
getContentInputStream in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException
See Also:
Channels.newInputStream(java.nio.channels.ReadableByteChannel)

getContent

public final void getContent(java.io.OutputStream os)
                      throws org.alfresco.service.cmr.repository.ContentIOException
Copies the input stream to the given OutputStream

Specified by:
getContent in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException

getContent

public final void getContent(java.io.File file)
                      throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
getContent in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException

getContentString

public final java.lang.String getContentString(int length)
                                        throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
getContentString in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException

getContentString

public final java.lang.String getContentString()
                                        throws org.alfresco.service.cmr.repository.ContentIOException
Makes use of the encoding, if available, to convert bytes to a string.

All the content is streamed into memory. So, like the interface said, be careful with this method.

Specified by:
getContentString in interface org.alfresco.service.cmr.repository.ContentReader
Throws:
org.alfresco.service.cmr.repository.ContentIOException
See Also:
ContentAccessor.getEncoding()

compareContentReaders

public static boolean compareContentReaders(org.alfresco.service.cmr.repository.ContentReader left,
                                            org.alfresco.service.cmr.repository.ContentReader right)
                                     throws org.alfresco.service.cmr.repository.ContentIOException
Does a comparison of the binaries associated with two readers. Several shortcuts are assumed to be valid:
- if the readers are the same instance, then the binaries are the same
- if the size field is different, then the binaries are different
Otherwise the binaries are compared.

Returns:
Returns true if the underlying binaries are the same
Throws:
org.alfresco.service.cmr.repository.ContentIOException


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