Package org.apache.commons.vfs.provider
Class DefaultFileContent
java.lang.Object
org.apache.commons.vfs.provider.DefaultFileContent
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionDefaultFileContent
(AbstractFileObject file, FileContentInfoFactory fileContentInfoFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes all resources used by the content, including all streams, readers and writers.getAttribute
(String attrName) Gets the value of an attribute.String[]
Lists the attributes of this file.Returns a read-only map of this file's attributes.Returns the certificates used to sign this file.get the content info.getFile()
Returns the file that this is the content of.Returns an input stream for reading the content.long
Returns the last-modified timestamp.Returns an output stream for writing the content.getOutputStream
(boolean bAppend) Returns an output stream for writing the content in append mode.Returns an input/output stream to use to read and write the content of the file in an random manner.long
getSize()
Returns the size of the content (in bytes).boolean
isOpen()
check if a input and/or output stream is open.
This checks only the scope of the current thread.boolean
check if a input and/or output stream is open.
This checks all threads.void
setAttribute
(String attrName, Object value) Sets the value of an attribute.void
setLastModifiedTime
(long modTime) Sets the last-modified timestamp.
-
Constructor Details
-
DefaultFileContent
-
-
Method Details
-
getFile
Returns the file that this is the content of.- Specified by:
getFile
in interfaceFileContent
-
getSize
Returns the size of the content (in bytes).- Specified by:
getSize
in 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
Returns the last-modified timestamp.- Specified by:
getLastModifiedTime
in 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
Sets the last-modified timestamp.- Specified by:
setLastModifiedTime
in 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
Returns a read-only map of this file's attributes.- Specified by:
getAttributes
in interfaceFileContent
- Throws:
FileSystemException
- If the file does not exist, or does not support attributes.
-
getAttributeNames
Lists the attributes of this file.- Specified by:
getAttributeNames
in interfaceFileContent
- Returns:
- The names of the attributes. Never returns null;
- Throws:
FileSystemException
- If the file does not exist, or does not support attributes.
-
getAttribute
Gets the value of an attribute.- Specified by:
getAttribute
in 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
Sets the value of an attribute.- Specified by:
setAttribute
in 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
Returns the certificates used to sign this file.- Specified by:
getCertificates
in 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
Returns an input stream for reading the content.- Specified by:
getInputStream
in 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
Returns an input/output stream to use to read and write the content of the file in an random manner.- Specified by:
getRandomAccessContent
in interfaceFileContent
- Throws:
FileSystemException
- If the file is read-only, or is being read, or is being written, or on error opening the stream.
-
getOutputStream
Returns an output stream for writing the content.- Specified by:
getOutputStream
in 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
Returns an output stream for writing the content in append mode.- Specified by:
getOutputStream
in 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
Closes all resources used by the content, including all streams, readers and writers.- Specified by:
close
in 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:
isOpen
in 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
get the content info. e.g. content-type, content-encoding- Specified by:
getContentInfo
in interfaceFileContent
- Throws:
FileSystemException
-