Class FileContentWriter

  • All Implemented Interfaces:
    org.alfresco.service.cmr.repository.ContentAccessor, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.MimetypeServiceAware
    Direct Known Subclasses:
    ContentCacheImpl.CacheWriter

    @AlfrescoPublicApi
    public class FileContentWriter
    extends AbstractContentWriter
    Provides direct access to a local file.

    This class does not provide remote access to the file.

    Author:
    Derek Hulley
    • Constructor Detail

      • FileContentWriter

        public FileContentWriter​(java.io.File file)
        Constructor that builds a URL based on the absolute path of the file.
        Parameters:
        file - the file for writing. This will most likely be directly related to the content URL.
      • FileContentWriter

        public FileContentWriter​(java.io.File file,
                                 org.alfresco.service.cmr.repository.ContentReader existingContentReader)
        Constructor that builds a URL based on the absolute path of the file.
        Parameters:
        file - the file for writing. This will most likely be directly related to the content URL.
        existingContentReader - a reader of a previous version of this content
      • FileContentWriter

        public FileContentWriter​(java.io.File file,
                                 java.lang.String url,
                                 org.alfresco.service.cmr.repository.ContentReader existingContentReader)
        Constructor that explicitely sets the URL that the reader represents.
        Parameters:
        file - the file for writing. This will most likely be directly related to the content URL.
        url - the relative url that the reader represents
        existingContentReader - a reader of a previous version of this content
    • Method Detail

      • getFile

        public java.io.File getFile()
        Returns:
        Returns the file that this writer accesses
      • getSize

        public long getSize()
        Returns:
        Returns the size of the underlying file or
      • createReader

        protected org.alfresco.service.cmr.repository.ContentReader createReader()
                                                                          throws org.alfresco.service.cmr.repository.ContentIOException
        The URL of the write is known from the start and this method contract states that no consideration needs to be taken w.r.t. the stream state.
        Specified by:
        createReader in class AbstractContentWriter
        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
      • getDirectWritableChannel

        protected java.nio.channels.WritableByteChannel getDirectWritableChannel()
                                                                          throws org.alfresco.service.cmr.repository.ContentIOException
        Description copied from class: AbstractContentWriter
        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.

        Specified by:
        getDirectWritableChannel in class AbstractContentWriter
        Returns:
        Returns a channel with which to write content
        Throws:
        org.alfresco.service.cmr.repository.ContentIOException - if the channel could not be opened
      • canWrite

        public boolean canWrite()
        Returns:
        Returns true always