Package org.alfresco.repo.content
Class AbstractContentWriter
- java.lang.Object
-
- org.alfresco.repo.content.AbstractContentAccessor
-
- org.alfresco.repo.content.AbstractContentWriter
-
- All Implemented Interfaces:
ContentAccessor,ContentWriter,MimetypeServiceAware
- Direct Known Subclasses:
FileContentWriter
@AlfrescoPublicApi public abstract class AbstractContentWriter extends AbstractContentAccessor implements ContentWriter, 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:getReader()to create a reader to the underlying contentgetDirectWritableChannel()to write content to the repository
- Author:
- Derek Hulley
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.alfresco.repo.content.AbstractContentAccessor
AbstractContentAccessor.CallbackFileChannel, AbstractContentAccessor.ChannelCloseCallbackAdvise
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractContentWriter(String contentUrl, ContentReader existingContentReader)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListener(ContentStreamListener listener)Adds the listener after checking that the output stream isn't already in use.protected abstract ContentReadercreateReader()A factory method for subclasses to implement that will ensure the proper implementation of theContentWriter.getReader()method.protected ContentLimitProvidergetContentLimitProvider()This method returns the configuredContentLimitProviderfor this writer.OutputStreamgetContentOutputStream()protected abstract WritableByteChannelgetDirectWritableChannel()Provides low-level access to write content to the repository.protected ContentReadergetExistingContentReader()FileChannelgetFileChannel(boolean truncate)ContentReadergetReader()Performs checks and copies required reader attributesWritableByteChannelgetWritableChannel()voidguessEncoding()When the content has been written, attempt to guess the encoding of it.voidguessMimetype(String filename)When the content has been written, attempt to guess the mimetype of it, using the filename and contents.booleanisChannelOpen()booleanisClosed()An automatically created listener sets the flagvoidputContent(File file)voidputContent(InputStream is)voidputContent(String content)Makes use of the encoding, if available, to convert the string to bytes.voidputContent(ContentReader reader)voidsetContentLimitProvider(ContentLimitProvider limitProvider)voidsetMimetypeService(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
getContentData, getContentUrl, getEncoding, getLocale, getMimetype, getSize, setEncoding, setLocale, setMimetype
-
-
-
-
Constructor Detail
-
AbstractContentWriter
protected AbstractContentWriter(String contentUrl, ContentReader existingContentReader)
- Parameters:
contentUrl- the content URLexistingContentReader- a reader of a previous version of this content
-
-
Method Detail
-
setContentLimitProvider
public void setContentLimitProvider(ContentLimitProvider limitProvider)
-
setMimetypeService
public void setMimetypeService(MimetypeService mimetypeService)
Supplies the Mimetype Service to be used when guessing encoding and mimetype information.- Specified by:
setMimetypeServicein interfaceMimetypeServiceAware
-
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:
addListenerin interfaceContentAccessor
-
createReader
protected abstract ContentReader createReader() throws ContentIOException
A factory method for subclasses to implement that will ensure the proper implementation of theContentWriter.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:
getReaderin interfaceContentWriter- Throws:
ContentIOException
-
getContentLimitProvider
protected ContentLimitProvider getContentLimitProvider()
This method returns the configuredContentLimitProviderfor this writer. By default aContentLimitProvider.NoLimitProviderwill be returned.- Since:
- Thor
-
isClosed
public final boolean isClosed()
An automatically created listener sets the flag- Specified by:
isClosedin interfaceContentWriter
-
isChannelOpen
public boolean isChannelOpen()
- Specified by:
isChannelOpenin interfaceContentAccessor
-
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
- Specified by:
getWritableChannelin interfaceContentWriter- Throws:
ContentIOException- See Also:
getDirectWritableChannel(),getCallbackWritableChannel(java.nio.channels.WritableByteChannel, List)
-
getFileChannel
public FileChannel getFileChannel(boolean truncate) throws ContentIOException
- Specified by:
getFileChannelin interfaceContentWriter- Throws:
ContentIOException
-
getContentOutputStream
public OutputStream getContentOutputStream() throws ContentIOException
- Specified by:
getContentOutputStreamin interfaceContentWriter- Throws:
ContentIOException- See Also:
Channels.newOutputStream(java.nio.channels.WritableByteChannel)
-
putContent
public void putContent(ContentReader reader) throws ContentIOException
- Specified by:
putContentin interfaceContentWriter- Throws:
ContentIOException- See Also:
ContentReader.getContentInputStream(),putContent(InputStream)
-
putContent
public final void putContent(InputStream is) throws ContentIOException
- Specified by:
putContentin interfaceContentWriter- Throws:
ContentIOException
-
putContent
public final void putContent(File file) throws ContentIOException
- Specified by:
putContentin interfaceContentWriter- 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:
putContentin interfaceContentWriter- 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:
guessEncodingin interfaceContentWriter- 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:
guessMimetypein interfaceContentWriter- See Also:
ContentWriter.guessMimetype(String)
-
-