Class FileContentReader
- java.lang.Object
-
- org.alfresco.repo.content.AbstractContentAccessor
-
- org.alfresco.repo.content.AbstractContentReader
-
- org.alfresco.repo.content.filestore.FileContentReader
-
- All Implemented Interfaces:
org.alfresco.service.cmr.repository.ContentAccessor,org.alfresco.service.cmr.repository.ContentReader,org.alfresco.service.cmr.repository.FileContentReader
@AlfrescoPublicApi public class FileContentReader extends AbstractContentReader implements org.alfresco.service.cmr.repository.FileContentReader
Provides direct access to a local file.This class does not provide remote access to the file.
- Author:
- Derek Hulley
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.alfresco.repo.content.AbstractContentAccessor
AbstractContentAccessor.CallbackFileChannel, AbstractContentAccessor.ChannelCloseCallbackAdvise
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMSG_MISSING_CONTENTmessage key for missing content.
-
Constructor Summary
Constructors Constructor Description FileContentReader(java.io.File file)Constructor that builds a URL based on the absolute path of the file.FileContentReader(java.io.File file, java.lang.String url)Constructor that explicitely sets the URL that the reader represents.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancanWrite()Deprecated.Since 5.1.protected org.alfresco.service.cmr.repository.ContentReadercreateReader()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.booleanexists()protected java.nio.channels.ReadableByteChannelgetDirectReadableChannel()Provides low-level access to read content from the repository.java.io.FilegetFile()longgetLastModified()static org.alfresco.service.cmr.repository.ContentReadergetSafeContentReader(org.alfresco.service.cmr.repository.ContentReader existingReader, java.lang.String msgTemplate, java.lang.Object... args)Checks the existing reader provided and replaces it with a reader onto some fake content if required.longgetSize()-
Methods inherited from class org.alfresco.repo.content.AbstractContentReader
addListener, compareContentReaders, getContent, getContent, getContentInputStream, getContentString, getContentString, getFileChannel, getLimits, getReadableChannel, getReader, getTransformerDebug, getUseBufferedInputStream, isChannelOpen, isClosed, setLimits, setTransformerDebug, setUseBufferedInputStream
-
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
-
-
-
-
Field Detail
-
MSG_MISSING_CONTENT
public static final java.lang.String MSG_MISSING_CONTENT
message key for missing content. Parameters areNodeRefContentReader
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FileContentReader
public FileContentReader(java.io.File file)
Constructor that builds a URL based on the absolute path of the file.- Parameters:
file- the file for reading. This will most likely be directly related to the content URL.
-
FileContentReader
public FileContentReader(java.io.File file, java.lang.String url)Constructor that explicitely sets the URL that the reader represents.- Parameters:
file- the file for reading. This will most likely be directly related to the content URL.url- the relative url that the reader represents
-
-
Method Detail
-
getSafeContentReader
public static org.alfresco.service.cmr.repository.ContentReader getSafeContentReader(org.alfresco.service.cmr.repository.ContentReader existingReader, java.lang.String msgTemplate, java.lang.Object... args)Checks the existing reader provided and replaces it with a reader onto some fake content if required. If the existing reader is invalid, an debug message will be logged under this classname category.It is a convenience method that clients can use to cheaply get a reader that is valid, regardless of whether the initial reader is valid.
- Parameters:
existingReader- a potentially invalid reader or nullmsgTemplate- the template message that will used to format the final fake contentargs- arguments to put into the fake content- Returns:
- Returns a the existing reader or a new reader onto some generated text content
-
getFile
public java.io.File getFile()
- Specified by:
getFilein interfaceorg.alfresco.service.cmr.repository.FileContentReader- Returns:
- Returns the file that this reader accesses
-
exists
public boolean exists()
- Specified by:
existsin interfaceorg.alfresco.service.cmr.repository.ContentReader- Specified by:
existsin interfaceorg.alfresco.service.cmr.repository.FileContentReader- Returns:
- Whether the file exists or not
-
getSize
public long getSize()
- Specified by:
getSizein interfaceorg.alfresco.service.cmr.repository.ContentAccessor- See Also:
File.length()
-
getLastModified
public long getLastModified()
- Specified by:
getLastModifiedin interfaceorg.alfresco.service.cmr.repository.ContentReader- See Also:
File.lastModified()
-
createReader
protected org.alfresco.service.cmr.repository.ContentReader createReader() throws org.alfresco.service.cmr.repository.ContentIOExceptionThe 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:
createReaderin classAbstractContentReader- Returns:
- Returns a reader onto the location referenced by this instance. The instance must always be a new instance.
- Throws:
org.alfresco.service.cmr.repository.ContentIOException
-
getDirectReadableChannel
protected java.nio.channels.ReadableByteChannel getDirectReadableChannel() throws org.alfresco.service.cmr.repository.ContentIOExceptionDescription copied from class:AbstractContentReaderProvides low-level access to read content from the repository.This is the only of the content reading methods that needs to be implemented by derived classes. All other content access methods make use of this in their underlying implementations.
- Specified by:
getDirectReadableChannelin classAbstractContentReader- Returns:
- Returns a channel from which content can be read
- Throws:
org.alfresco.service.cmr.repository.ContentIOException- if the channel could not be opened or the underlying content has disappeared
-
canWrite
@Deprecated public boolean canWrite()
Deprecated.Since 5.1. This method has no value: a file reader can never write (DH: 2015/02/17)- Returns:
- Returns false as this is a reader
-
-