Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

org.alfresco.repo.content
Class AbstractContentReader
java.lang.Object
  org.alfresco.repo.content.AbstractContentReader
All Implemented Interfaces:
ContentReader, ContentAccessor
Direct Known Subclasses:
FileContentReader

public abstract class AbstractContentReader
extends Object
implements ContentReader, ContentAccessor
Implements all the convenience methods of the interface. The only methods that need to be implemented, i.e. provide low-level content access are:
Author:
Derek Hulley

Constructor Summary
protected
AbstractContentReader(String contentUrl)
Method Summary
void
addListener(ContentStreamListener listener)
          Adds the listener after checking that the output stream isn't already in use.
protected void
channelOpened()
          Derived classes can call this method to ensure that necessary trace logging is performed when the IO Channel is opened.
static boolean
compareContentReaders(ContentReader left, ContentReader right)
          Does a comparison of the binaries associated with two readers.
protected abstract ContentReader
createReader()
          A factory method for subclasses to implement that will ensure the proper implementation of the ContentReader.getReader() method.
protected void
finalize()
protected FileChannel
getCallbackFileChannel(FileChannel directChannel, List<ContentStreamListener> listeners)
          Generate a callback instance of the FileChannel.
void
getContent(File file)
          Gets content from the repository direct to file
void
getContent(OutputStream os)
          Copies the input stream to the given OutputStream
getContentData()
          Get the data representation of the content being accessed.
getContentInputStream()
          Get a stream to read from the underlying channel
getContentString()
          Makes use of the encoding, if available, to convert bytes to a string.
getContentString(int length)
          Gets content from the repository direct to String, but limiting the string size to a given number of characters.
getContentUrl()
          Retrieve the URL that this accessor references
protected abstract ReadableByteChannel
getDirectReadableChannel()
          Provides low-level access to read content from the repository.
getEncoding()
          Get the encoding of the content being accessed
getFileChannel()
          Provides read-only, random-access to the underlying content.
getLimits()
getLocale()
          Get the locale of the content being accessed
getMimetype()
          Get the content mimetype
getReadableChannel()
          Provides low-level access to the underlying content.
getReader()
          Performs checks and copies required reader attributes
getTransformerDebug()
boolean
getUseBufferedInputStream()
boolean
isChannelOpen()
          Gets the open/close state of the underlying IO Channel.
boolean
isClosed()
          An automatically created listener sets the flag
protected void
setContentUrl(String contentUrl)
          Allow derived implementations to set the Content URL.
void
setEncoding(String encoding)
          Set the String encoding for this accessor
void
setLimits(TransformationOptionLimits limits)
void
setLocale(Locale locale)
          Set the Locale for this accessor
void
setMimetype(String mimetype)
          Set the mimetype that must be used for accessing the content.
void
setTransformerDebug(TransformerDebug transformerDebug)
void
setUseBufferedInputStream(boolean useBufferedInputStream)
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.ContentAccessor
getSize
Methods inherited from interface org.alfresco.service.cmr.repository.ContentReader
exists, getLastModified
Constructor Detail
AbstractContentReader
protected AbstractContentReader(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
setLimits
public void setLimits(TransformationOptionLimits limits)

getLimits
public TransformationOptionLimits getLimits()

setTransformerDebug
public void setTransformerDebug(TransformerDebug transformerDebug)

getTransformerDebug
public TransformerDebug getTransformerDebug()

setUseBufferedInputStream
public void setUseBufferedInputStream(boolean useBufferedInputStream)

getUseBufferedInputStream
public boolean getUseBufferedInputStream()

addListener
public void addListener(ContentStreamListener listener)
Adds the listener after checking that the output stream isn't already in use.
Specified by:
addListener in interface ContentAccessor
Parameters:
listener - a listener that will be called for output stream event notification

createReader
protected abstract ContentReader createReader()
                                       throws 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:
ContentIOException

getReader
public final ContentReader getReader()
                              throws ContentIOException
Performs checks and copies required reader attributes
Specified by:
getReader in interface ContentReader
Returns:
Returns a reader onto the underlying content
Throws:
ContentIOException

isClosed
public final boolean isClosed()
An automatically created listener sets the flag
Specified by:
isClosed in interface ContentReader
Returns:
Return true if the content input stream has been used and closed otherwise false.

isChannelOpen
public boolean isChannelOpen()
Description copied from interface: ContentAccessor
Gets the open/close state of the underlying IO Channel.
Specified by:
isChannelOpen in interface ContentAccessor
Returns:
Returns true if the underlying IO Channel is open

getDirectReadableChannel
protected abstract ReadableByteChannel getDirectReadableChannel()
                                                         throws 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:
ContentIOException - if the channel could not be opened or the underlying content has disappeared

getReadableChannel
public final ReadableByteChannel getReadableChannel()
                                             throws ContentIOException
Description copied from interface: ContentReader
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.

Specified by:
getReadableChannel in interface ContentReader
Returns:
Returns a stream that can be read at will, but must be closed when completed
Throws:
ContentIOException
See Also:
getDirectReadableChannel(), getCallbackReadableChannel(ReadableByteChannel, List)

getFileChannel
public 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().
Specified by:
getFileChannel in interface ContentReader
Returns:
Returns a random-access channel onto the content
Throws:
ContentIOException

getContentInputStream
public InputStream getContentInputStream()
                                  throws ContentIOException
Description copied from interface: ContentReader
Get a stream to read from the underlying channel
Specified by:
getContentInputStream in interface ContentReader
Returns:
Returns an input stream onto the underlying channel
Throws:
ContentIOException
See Also:
Channels.newInputStream(java.nio.channels.ReadableByteChannel)

getContent
public final void getContent(OutputStream os)
                      throws ContentIOException
Copies the input stream to the given OutputStream
Specified by:
getContent in interface ContentReader
Parameters:
os - the stream to which to write the content
Throws:
ContentIOException

getContent
public final void getContent(File file)
                      throws ContentIOException
Description copied from interface: ContentReader
Gets content from the repository direct to file

All resources will be closed automatically.

Specified by:
getContent in interface ContentReader
Parameters:
file - the file to write the content to - it will be overwritten
Throws:
ContentIOException

getContentString
public final String getContentString(int length)
                              throws ContentIOException
Description copied from interface: ContentReader
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.

Specified by:
getContentString in interface ContentReader
Parameters:
length - the maximum number of characters to retrieve
Returns:
Returns a truncated String representation of the content
Throws:
ContentIOException

getContentString
public final String getContentString()
                              throws 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 ContentReader
Returns:
Returns a String representation of the content
Throws:
ContentIOException
See Also:
ContentAccessor.getEncoding()

compareContentReaders
public static boolean compareContentReaders(ContentReader left,
                                            ContentReader right)
                                     throws 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:
ContentIOException

finalize
protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

toString
public String toString()
Overrides:
toString in class Object

getContentData
public ContentData getContentData()
Description copied from interface: ContentAccessor
Get the data representation of the content being accessed.

The content mimetype must be set before this method is called as the content data requires a mimetype whenever the content URL is specified.

Specified by:
getContentData in interface ContentAccessor
Returns:
Returns the content data

channelOpened
protected final void channelOpened()
Derived classes can call this method to ensure that necessary trace logging is performed when the IO Channel is opened.

getContentUrl
public String getContentUrl()
Description copied from interface: ContentAccessor
Retrieve the URL that this accessor references
Specified by:
getContentUrl in interface ContentAccessor
Returns:
the content URL

setContentUrl
protected void setContentUrl(String contentUrl)
Allow derived implementations to set the Content URL. This allows for implementations where the URL is not known when the accessor is first constructed.
Parameters:
contentUrl - the new content URL

getMimetype
public String getMimetype()
Description copied from interface: ContentAccessor
Get the content mimetype
Specified by:
getMimetype in interface ContentAccessor
Returns:
Returns a content mimetype

setMimetype
public void setMimetype(String mimetype)
Description copied from interface: ContentAccessor
Set the mimetype that must be used for accessing the content.

When dealing with a ContentWriter, you may wish to use ContentWriter.guessMimetype(String) to have this set for you based on the filename and contents.

Specified by:
setMimetype in interface ContentAccessor
Parameters:
mimetype - the underlying content's mimetype - null if unknown

getEncoding
public String getEncoding()
Description copied from interface: ContentAccessor
Get the encoding of the content being accessed
Specified by:
getEncoding in interface ContentAccessor
Returns:
Returns the content encoding - null if unknown

setEncoding
public void setEncoding(String encoding)
Description copied from interface: ContentAccessor
Set the String encoding for this accessor

When dealing with a ContentWriter, you may wish to use ContentWriter.guessMimetype(String) to have this set for you based on the contents.

Specified by:
setEncoding in interface ContentAccessor
Parameters:
encoding - the underlying content's encoding - null if unknown

getLocale
public Locale getLocale()
Description copied from interface: ContentAccessor
Get the locale of the content being accessed
Specified by:
getLocale in interface ContentAccessor
Returns:
Returns the content locale or null if unkown

setLocale
public void setLocale(Locale locale)
Description copied from interface: ContentAccessor
Set the Locale for this accessor
Specified by:
setLocale in interface ContentAccessor
Parameters:
locale - the content's locale, if known.

getCallbackFileChannel
protected FileChannel getCallbackFileChannel(FileChannel directChannel,
                                             List<ContentStreamListener> listeners)
                                      throws ContentIOException
Generate a callback instance of the FileChannel.
Parameters:
directChannel - the delegate that to perform the actual operations
listeners - the listeners to call
Returns:
Returns a new channel that functions just like the original, except that it issues callbacks to the listeners
Throws:
ContentIOException

Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005–2016 Alfresco Software. All rights reserved.

Java API documentation generated with DocFlex/Javadoc 1.6.1 using JavadocPro template set.