Class 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:
    Author:
    Derek Hulley
    • Constructor Detail

      • AbstractContentWriter

        protected AbstractContentWriter​(java.lang.String contentUrl,
                                        org.alfresco.service.cmr.repository.ContentReader existingContentReader)
        Parameters:
        contentUrl - the content URL
        existingContentReader - a reader of a previous version of this content
    • 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:
        setMimetypeService in interface org.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:
        addListener in interface org.alfresco.service.cmr.repository.ContentAccessor
      • createReader

        protected abstract org.alfresco.service.cmr.repository.ContentReader createReader()
                                                                                   throws org.alfresco.service.cmr.repository.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:
        org.alfresco.service.cmr.repository.ContentIOException
      • getReader

        public final org.alfresco.service.cmr.repository.ContentReader getReader()
                                                                          throws org.alfresco.service.cmr.repository.ContentIOException
        Performs checks and copies required reader attributes
        Specified by:
        getReader in interface org.alfresco.service.cmr.repository.ContentWriter
        Throws:
        org.alfresco.service.cmr.repository.ContentIOException
      • isClosed

        public final boolean isClosed()
        An automatically created listener sets the flag
        Specified by:
        isClosed in interface org.alfresco.service.cmr.repository.ContentWriter
      • isChannelOpen

        public boolean isChannelOpen()
        Specified by:
        isChannelOpen in interface org.alfresco.service.cmr.repository.ContentAccessor
      • getDirectWritableChannel

        protected abstract java.nio.channels.WritableByteChannel getDirectWritableChannel()
                                                                                   throws org.alfresco.service.cmr.repository.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:
        org.alfresco.service.cmr.repository.ContentIOException - if the channel could not be opened
      • getFileChannel

        public java.nio.channels.FileChannel getFileChannel​(boolean truncate)
                                                     throws org.alfresco.service.cmr.repository.ContentIOException
        Specified by:
        getFileChannel in interface org.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:
        getContentOutputStream in interface org.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:
        putContent in interface org.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:
        putContent in interface org.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:
        putContent in interface org.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.ContentIOException
        Makes use of the encoding, if available, to convert the string to bytes.
        Specified by:
        putContent in interface org.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:
        guessEncoding in interface org.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:
        guessMimetype in interface org.alfresco.service.cmr.repository.ContentWriter
        See Also:
        ContentWriter.guessMimetype(String)