Package org.apache.commons.vfs.provider
Class DefaultFileContent
- java.lang.Object
-
- org.apache.commons.vfs.provider.DefaultFileContent
-
- All Implemented Interfaces:
FileContent
public final class DefaultFileContent extends java.lang.Object implements FileContent
The content of a file.- Version:
- $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Wed, 29 Nov 2006) $
- Author:
- Adam Murdoch
-
-
Constructor Summary
Constructors Constructor Description DefaultFileContent(AbstractFileObject file, FileContentInfoFactory fileContentInfoFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes all resources used by the content, including all streams, readers and writers.java.lang.ObjectgetAttribute(java.lang.String attrName)Gets the value of an attribute.java.lang.String[]getAttributeNames()Lists the attributes of this file.java.util.MapgetAttributes()Returns a read-only map of this file's attributes.java.security.cert.Certificate[]getCertificates()Returns the certificates used to sign this file.FileContentInfogetContentInfo()get the content info.FileObjectgetFile()Returns the file that this is the content of.java.io.InputStreamgetInputStream()Returns an input stream for reading the content.longgetLastModifiedTime()Returns the last-modified timestamp.java.io.OutputStreamgetOutputStream()Returns an output stream for writing the content.java.io.OutputStreamgetOutputStream(boolean bAppend)Returns an output stream for writing the content in append mode.RandomAccessContentgetRandomAccessContent(RandomAccessMode mode)Returns an input/output stream to use to read and write the content of the file in an random manner.longgetSize()Returns the size of the content (in bytes).booleanisOpen()check if a input and/or output stream is open.
This checks only the scope of the current thread.booleanisOpenGlobal()check if a input and/or output stream is open.
This checks all threads.voidsetAttribute(java.lang.String attrName, java.lang.Object value)Sets the value of an attribute.voidsetLastModifiedTime(long modTime)Sets the last-modified timestamp.
-
-
-
Constructor Detail
-
DefaultFileContent
public DefaultFileContent(AbstractFileObject file, FileContentInfoFactory fileContentInfoFactory)
-
-
Method Detail
-
getFile
public FileObject getFile()
Returns the file that this is the content of.- Specified by:
getFilein interfaceFileContent
-
getSize
public long getSize() throws FileSystemExceptionReturns the size of the content (in bytes).- Specified by:
getSizein interfaceFileContent- Returns:
- The size of the file, in bytes.
- Throws:
FileSystemException- If the file does not exist, or is being written to, or on error determining the size.
-
getLastModifiedTime
public long getLastModifiedTime() throws FileSystemExceptionReturns the last-modified timestamp.- Specified by:
getLastModifiedTimein interfaceFileContent- Returns:
- The last-modified timestamp.
- Throws:
FileSystemException- If the file does not exist, or is being written to, or on error determining the last-modified timestamp.
-
setLastModifiedTime
public void setLastModifiedTime(long modTime) throws FileSystemExceptionSets the last-modified timestamp.- Specified by:
setLastModifiedTimein interfaceFileContent- Parameters:
modTime- The time to set the last-modified timestamp to.- Throws:
FileSystemException- If the file is read-only, or is being written to, or on error setting the last-modified timestamp.
-
getAttributes
public java.util.Map getAttributes() throws FileSystemExceptionReturns a read-only map of this file's attributes.- Specified by:
getAttributesin interfaceFileContent- Throws:
FileSystemException- If the file does not exist, or does not support attributes.
-
getAttributeNames
public java.lang.String[] getAttributeNames() throws FileSystemExceptionLists the attributes of this file.- Specified by:
getAttributeNamesin interfaceFileContent- Returns:
- The names of the attributes. Never returns null;
- Throws:
FileSystemException- If the file does not exist, or does not support attributes.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String attrName) throws FileSystemExceptionGets the value of an attribute.- Specified by:
getAttributein interfaceFileContent- Parameters:
attrName- The name of the attribute. Attribute names are case insensitive.- Returns:
- The value of the attribute, or null if the attribute value is unknown.
- Throws:
FileSystemException- If the file does not exist, or does not support attributes.
-
setAttribute
public void setAttribute(java.lang.String attrName, java.lang.Object value) throws FileSystemExceptionSets the value of an attribute.- Specified by:
setAttributein interfaceFileContent- Parameters:
attrName- The name of the attribute.value- The value of the attribute.- Throws:
FileSystemException- If the file does not exist, or is read-only, or does not support attributes, or on error setting the attribute.
-
getCertificates
public java.security.cert.Certificate[] getCertificates() throws FileSystemExceptionReturns the certificates used to sign this file.- Specified by:
getCertificatesin interfaceFileContent- Returns:
- The certificates, or an empty array if there are no certificates or the file does not support signing.
- Throws:
FileSystemException- If the file does not exist, or is being written.
-
getInputStream
public java.io.InputStream getInputStream() throws FileSystemExceptionReturns an input stream for reading the content.- Specified by:
getInputStreamin interfaceFileContent- Returns:
- An input stream to read the file's content from. The input
stream is buffered, so there is no need to wrap it in a
BufferedInputStream. - Throws:
FileSystemException- If the file does not exist, or is being read, or is being written, or on error opening the stream.
-
getRandomAccessContent
public RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
Returns an input/output stream to use to read and write the content of the file in an random manner.- Specified by:
getRandomAccessContentin interfaceFileContent- Throws:
FileSystemException- If the file is read-only, or is being read, or is being written, or on error opening the stream.
-
getOutputStream
public java.io.OutputStream getOutputStream() throws FileSystemExceptionReturns an output stream for writing the content.- Specified by:
getOutputStreamin interfaceFileContent- Returns:
- An output stream to write the file's content to. The stream is
buffered, so there is no need to wrap it in a
BufferedOutputStream. - Throws:
FileSystemException- If the file is read-only, or is being read, or is being written, or on error opening the stream.
-
getOutputStream
public java.io.OutputStream getOutputStream(boolean bAppend) throws FileSystemExceptionReturns an output stream for writing the content in append mode.- Specified by:
getOutputStreamin interfaceFileContent- Parameters:
bAppend- true if you would like to append to the file- Returns:
- An output stream to write the file's content to. The stream is
buffered, so there is no need to wrap it in a
BufferedOutputStream. - Throws:
FileSystemException- If the file is read-only, or is being read, or is being written, or on error opening the stream.
-
close
public void close() throws FileSystemExceptionCloses all resources used by the content, including all streams, readers and writers.- Specified by:
closein interfaceFileContent- Throws:
FileSystemException
-
isOpen
public boolean isOpen()
check if a input and/or output stream is open.
This checks only the scope of the current thread.- Specified by:
isOpenin interfaceFileContent- Returns:
- true if this is the case
-
isOpenGlobal
public boolean isOpenGlobal()
check if a input and/or output stream is open.
This checks all threads.- Returns:
- true if this is the case
-
getContentInfo
public FileContentInfo getContentInfo() throws FileSystemException
get the content info. e.g. content-type, content-encoding- Specified by:
getContentInfoin interfaceFileContent- Throws:
FileSystemException
-
-