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 AbstractContentWriter
java.lang.Object
  org.alfresco.repo.content.AbstractContentAccessor
      org.alfresco.repo.content.AbstractContentWriter
All Implemented Interfaces:
ContentWriter, ContentAccessor, org.alfresco.service.cmr.repository.MimetypeServiceAware
Direct Known Subclasses:
FileContentWriter

@org.alfresco.api.AlfrescoPublicApi
public abstract class AbstractContentWriter
extends org.alfresco.repo.content.AbstractContentAccessor
implements ContentWriter, org.alfresco.service.cmr.repository.MimetypeServiceAware
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

Nested classes/interfaces inherited from class org.alfresco.repo.content.AbstractContentAccessor
AbstractContentAccessor.CallbackFileChannel, AbstractContentAccessor.ChannelCloseCallbackAdvise
Constructor Summary
protected
AbstractContentWriter(String contentUrl, ContentReader existingContentReader)
Method Summary
void
addListener(ContentStreamListener listener)
          Adds the listener after checking that the output stream isn't already in use.
protected abstract ContentReader
createReader()
          A factory method for subclasses to implement that will ensure the proper implementation of the ContentWriter.getReader() method.
protected org.alfresco.repo.content.ContentLimitProvider
getContentLimitProvider()
          This method returns the configured ContentLimitProvider for this writer.
getContentOutputStream()
          Get a stream to write to the underlying channel.
protected abstract WritableByteChannel
getDirectWritableChannel()
          Provides low-level access to write content to the repository.
protected ContentReader
getExistingContentReader()
getFileChannel(boolean truncate)
          Provides read-write, random-access to the underlying content.
getReader()
          Performs checks and copies required reader attributes
getWritableChannel()
          Provides low-level access to write to repository content.
void
guessEncoding()
          When the content has been written, attempt to guess the encoding of it.
void
guessMimetype(String filename)
          When the content has been written, attempt to guess the mimetype of it, using the filename and contents.
boolean
isChannelOpen()
          Gets the open/close state of the underlying IO Channel.
boolean
isClosed()
          An automatically created listener sets the flag
void
putContent(ContentReader reader)
          Copies content from the reader.
void
putContent(File file)
          Puts content to the repository direct from file
void
putContent(InputStream is)
          Puts content to the repository
void
putContent(String content)
          Makes use of the encoding, if available, to convert the string to bytes.
void
setContentLimitProvider(org.alfresco.repo.content.ContentLimitProvider limitProvider)
void
setMimetypeService(MimetypeService mimetypeService)
          Supplies the Mimetype Service to be used when guessing encoding and mimetype information.
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.ContentAccessor
getSize
Constructor Detail
AbstractContentWriter
protected AbstractContentWriter(String contentUrl,
                                ContentReader existingContentReader)
Parameters:
contentUrl - the content URL
existingContentReader - a reader of a previous version of this content
Method Detail
setContentLimitProvider
public void setContentLimitProvider(org.alfresco.repo.content.ContentLimitProvider limitProvider)

setMimetypeService
public void setMimetypeService(MimetypeService mimetypeService)
Supplies the Mimetype Service to be used when guessing encoding and mimetype information.
Specified by:
setMimetypeService in interface org.alfresco.service.cmr.repository.MimetypeServiceAware

getExistingContentReader
protected ContentReader getExistingContentReader()
Returns:
Returns a reader onto the previous version of this content

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 ContentWriter.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 and never null.
Throws:
ContentIOException

getReader
public final ContentReader getReader()
                              throws ContentIOException
Performs checks and copies required reader attributes
Specified by:
getReader in interface ContentWriter
Returns:
Returns a reader onto the underlying content that this writer will or has written to
Throws:
ContentIOException

getContentLimitProvider
protected org.alfresco.repo.content.ContentLimitProvider getContentLimitProvider()
This method returns the configured ContentLimitProvider for this writer. By default a ContentLimitProvider.NoLimitProvider will be returned.
Since:
Thor

isClosed
public final boolean isClosed()
An automatically created listener sets the flag
Specified by:
isClosed in interface ContentWriter
Returns:
Return true if the content output 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

getDirectWritableChannel
protected abstract WritableByteChannel getDirectWritableChannel()
                                                         throws ContentIOException
Provides low-level access to write content to the repository.

This is the only of the content writing 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 with which to write content
Throws:
ContentIOException - if the channel could not be opened

getWritableChannel
public final WritableByteChannel getWritableChannel()
                                             throws ContentIOException
Description copied from interface: ContentWriter
Provides low-level access to write to repository content.

The channel returned to the client should remain open (subject to timeouts) until closed by the client. All lock detection, read-only access and other concurrency issues are dealt with during this operation. It remains possible that implementations will throw exceptions when the channel is closed.

The stream will notify any listeners according to the listener interface.

Specified by:
getWritableChannel in interface ContentWriter
Returns:
Returns a channel with which to write content
Throws:
ContentIOException
See Also:
getDirectWritableChannel(), getCallbackWritableChannel(java.nio.channels.WritableByteChannel, List)

getFileChannel
public FileChannel getFileChannel(boolean truncate)
                           throws ContentIOException
Provides read-write, random-access to the underlying content. In general, this method should be considered more expensive than the sequential-access method, ContentWriter.getWritableChannel().

Underlying implementations use the truncate parameter to determine the most effective means of providing access to the content.

Specified by:
getFileChannel in interface ContentWriter
Parameters:
truncate - true to start with zero length content
Returns:
Returns a random-access channel onto the content
Throws:
ContentIOException

getContentOutputStream
public OutputStream getContentOutputStream()
                                    throws ContentIOException
Description copied from interface: ContentWriter
Get a stream to write to the underlying channel.
Specified by:
getContentOutputStream in interface ContentWriter
Returns:
Returns an output stream onto the underlying channel
Throws:
ContentIOException
See Also:
Channels.newOutputStream(java.nio.channels.WritableByteChannel)

putContent
public void putContent(ContentReader reader)
                throws ContentIOException
Description copied from interface: ContentWriter
Copies content from the reader.

All resources will be closed automatically.

Specified by:
putContent in interface ContentWriter
Parameters:
reader - the reader acting as the source of the content
Throws:
ContentIOException
See Also:
ContentReader.getContentInputStream(), putContent(InputStream)

putContent
public final void putContent(InputStream is)
                      throws ContentIOException
Description copied from interface: ContentWriter
Puts content to the repository

All resources will be closed automatically.

Specified by:
putContent in interface ContentWriter
Parameters:
is - the input stream from which the content will be read
Throws:
ContentIOException

putContent
public final void putContent(File file)
                      throws ContentIOException
Description copied from interface: ContentWriter
Puts content to the repository direct from file

All resources will be closed automatically.

Specified by:
putContent in interface ContentWriter
Parameters:
file - the file to load the content from
Throws:
ContentIOException

putContent
public final void putContent(String content)
                      throws ContentIOException
Makes use of the encoding, if available, to convert the string to bytes.
Specified by:
putContent in interface ContentWriter
Parameters:
content - a string representation of the content
Throws:
ContentIOException
See Also:
ContentAccessor.getEncoding()

guessEncoding
public void guessEncoding()
When the content has been written, attempt to guess the encoding of it.
Specified by:
guessEncoding in interface ContentWriter
See Also:
ContentWriter.guessEncoding()

guessMimetype
public void guessMimetype(String filename)
When the content has been written, attempt to guess the mimetype of it, using the filename and contents.
Specified by:
guessMimetype in interface ContentWriter
Parameters:
filename - The filename of the content (if known)
See Also:
ContentWriter.guessMimetype(String)

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–2018 Alfresco Software. All rights reserved.

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