Package org.alfresco.repo.content
Class AbstractContentWriter
- java.lang.Object
-
- org.alfresco.repo.content.AbstractContentAccessor
-
- org.alfresco.repo.content.AbstractContentWriter
-
- All Implemented Interfaces:
org.alfresco.service.cmr.repository.ContentAccessor,org.alfresco.service.cmr.repository.ContentWriter,org.alfresco.service.cmr.repository.MimetypeServiceAware
- Direct Known Subclasses:
FileContentWriter
@AlfrescoPublicApi public abstract class AbstractContentWriter extends AbstractContentAccessor implements org.alfresco.service.cmr.repository.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: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(java.lang.String contentUrl, org.alfresco.service.cmr.repository.ContentReader existingContentReader)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListener(org.alfresco.service.cmr.repository.ContentStreamListener listener)Adds the listener after checking that the output stream isn't already in use.protected abstract org.alfresco.service.cmr.repository.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.java.io.OutputStreamgetContentOutputStream()protected abstract java.nio.channels.WritableByteChannelgetDirectWritableChannel()Provides low-level access to write content to the repository.protected org.alfresco.service.cmr.repository.ContentReadergetExistingContentReader()java.nio.channels.FileChannelgetFileChannel(boolean truncate)org.alfresco.service.cmr.repository.ContentReadergetReader()Performs checks and copies required reader attributesjava.nio.channels.WritableByteChannelgetWritableChannel()voidguessEncoding()When the content has been written, attempt to guess the encoding of it.voidguessMimetype(java.lang.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(java.io.File file)voidputContent(java.io.InputStream is)voidputContent(java.lang.String content)Makes use of the encoding, if available, to convert the string to bytes.voidputContent(org.alfresco.service.cmr.repository.ContentReader reader)voidsetContentLimitProvider(ContentLimitProvider limitProvider)voidsetMimetypeService(org.alfresco.service.cmr.repository.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
-
-
-
-
Method Detail
-
setContentLimitProvider
public void setContentLimitProvider(ContentLimitProvider limitProvider)
-
setMimetypeService
public void setMimetypeService(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)
Supplies the Mimetype Service to be used when guessing encoding and mimetype information.- Specified by:
setMimetypeServicein interfaceorg.alfresco.service.cmr.repository.MimetypeServiceAware
-
getExistingContentReader
protected org.alfresco.service.cmr.repository.ContentReader getExistingContentReader()
- Returns:
- Returns a reader onto the previous version of this content
-
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:
addListenerin interfaceorg.alfresco.service.cmr.repository.ContentAccessor
-
createReader
protected abstract org.alfresco.service.cmr.repository.ContentReader createReader() throws org.alfresco.service.cmr.repository.ContentIOExceptionA 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:
org.alfresco.service.cmr.repository.ContentIOException
-
getReader
public final org.alfresco.service.cmr.repository.ContentReader getReader() throws org.alfresco.service.cmr.repository.ContentIOExceptionPerforms checks and copies required reader attributes- Specified by:
getReaderin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.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 interfaceorg.alfresco.service.cmr.repository.ContentWriter
-
isChannelOpen
public boolean isChannelOpen()
- Specified by:
isChannelOpenin interfaceorg.alfresco.service.cmr.repository.ContentAccessor
-
getDirectWritableChannel
protected abstract java.nio.channels.WritableByteChannel getDirectWritableChannel() throws org.alfresco.service.cmr.repository.ContentIOExceptionProvides 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:
org.alfresco.service.cmr.repository.ContentIOException- if the channel could not be opened
-
getWritableChannel
public final java.nio.channels.WritableByteChannel getWritableChannel() throws org.alfresco.service.cmr.repository.ContentIOException- Specified by:
getWritableChannelin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.ContentIOException- See Also:
getDirectWritableChannel(),getCallbackWritableChannel(java.nio.channels.WritableByteChannel, List)
-
getFileChannel
public java.nio.channels.FileChannel getFileChannel(boolean truncate) throws org.alfresco.service.cmr.repository.ContentIOException- Specified by:
getFileChannelin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.ContentIOException
-
getContentOutputStream
public java.io.OutputStream getContentOutputStream() throws org.alfresco.service.cmr.repository.ContentIOException- Specified by:
getContentOutputStreamin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.ContentIOException- See Also:
Channels.newOutputStream(java.nio.channels.WritableByteChannel)
-
putContent
public void putContent(org.alfresco.service.cmr.repository.ContentReader reader) throws org.alfresco.service.cmr.repository.ContentIOException- Specified by:
putContentin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.ContentIOException- See Also:
ContentReader.getContentInputStream(),putContent(InputStream)
-
putContent
public final void putContent(java.io.InputStream is) throws org.alfresco.service.cmr.repository.ContentIOException- Specified by:
putContentin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.ContentIOException
-
putContent
public final void putContent(java.io.File file) throws org.alfresco.service.cmr.repository.ContentIOException- Specified by:
putContentin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.ContentIOException
-
putContent
public final void putContent(java.lang.String content) throws org.alfresco.service.cmr.repository.ContentIOExceptionMakes use of the encoding, if available, to convert the string to bytes.- Specified by:
putContentin interfaceorg.alfresco.service.cmr.repository.ContentWriter- Throws:
org.alfresco.service.cmr.repository.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 interfaceorg.alfresco.service.cmr.repository.ContentWriter- See Also:
ContentWriter.guessEncoding()
-
guessMimetype
public void guessMimetype(java.lang.String filename)
When the content has been written, attempt to guess the mimetype of it, using the filename and contents.- Specified by:
guessMimetypein interfaceorg.alfresco.service.cmr.repository.ContentWriter- See Also:
ContentWriter.guessMimetype(String)
-
-