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
ConstructorsModifierConstructorDescriptionprotectedAbstractContentWriter(String contentUrl, ContentReader existingContentReader) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ContentStreamListener listener) Adds the listener after checking that the output stream isn't already in use.protected abstract ContentReaderA factory method for subclasses to implement that will ensure the proper implementation of theContentWriter.getReader()method.protected ContentLimitProviderThis method returns the configuredContentLimitProviderfor this writer.protected abstract WritableByteChannelProvides low-level access to write content to the repository.protected ContentReadergetFileChannel(boolean truncate) final ContentReaderPerforms checks and copies required reader attributesfinal WritableByteChannelvoidWhen 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.booleanfinal booleanisClosed()An automatically created listener sets the flagfinal voidputContent(File file) final voidfinal 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, toStringMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.alfresco.service.cmr.repository.ContentAccessor
getContentData, getContentUrl, getEncoding, getLocale, getMimetype, getSize, setEncoding, setLocale, setMimetype
-
Constructor Details
-
AbstractContentWriter
- Parameters:
contentUrl- the content URLexistingContentReader- a reader of a previous version of this content
-
-
Method Details
-
setContentLimitProvider
-
setMimetypeService
Supplies the Mimetype Service to be used when guessing encoding and mimetype information.- Specified by:
setMimetypeServicein interfaceMimetypeServiceAware
-
getExistingContentReader
- Returns:
- Returns a reader onto the previous version of this content
-
addListener
Adds the listener after checking that the output stream isn't already in use.- Specified by:
addListenerin interfaceContentAccessor
-
createReader
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
Performs checks and copies required reader attributes- Specified by:
getReaderin interfaceContentWriter- Throws:
ContentIOException
-
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
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
- Specified by:
getWritableChannelin interfaceContentWriter- Throws:
ContentIOException- See Also:
-
getDirectWritableChannel()getCallbackWritableChannel(java.nio.channels.WritableByteChannel, List)
-
getFileChannel
- Specified by:
getFileChannelin interfaceContentWriter- Throws:
ContentIOException
-
getContentOutputStream
- Specified by:
getContentOutputStreamin interfaceContentWriter- Throws:
ContentIOException- See Also:
-
putContent
- Specified by:
putContentin interfaceContentWriter- Throws:
ContentIOException- See Also:
-
putContent
- Specified by:
putContentin interfaceContentWriter- Throws:
ContentIOException
-
putContent
- Specified by:
putContentin interfaceContentWriter- Throws:
ContentIOException
-
putContent
Makes use of the encoding, if available, to convert the string to bytes.- Specified by:
putContentin interfaceContentWriter- Throws:
ContentIOException- See Also:
-
guessEncoding
public void guessEncoding()When the content has been written, attempt to guess the encoding of it.- Specified by:
guessEncodingin interfaceContentWriter- See Also:
-
guessMimetype
When the content has been written, attempt to guess the mimetype of it, using the filename and contents.- Specified by:
guessMimetypein interfaceContentWriter- See Also:
-