Package org.apache.commons.vfs2.provider
Class DefaultFileContent
java.lang.Object
org.apache.commons.vfs2.provider.DefaultFileContent
- All Implemented Interfaces:
Closeable
,AutoCloseable
,FileContent
The content of a file.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultFileContent
(AbstractFileObject fileObject, FileContentInfoFactory fileContentInfoFactory) Constructs a new instance. -
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.Gets the FileContentInfo which describes the content-type, content-encoding.getFile()
Returns the file that this is the content of.Returns an input stream for reading the content.getInputStream
(int bufferSize) 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.getOutputStream
(boolean bAppend, int bufferSize) Returns an output stream for writing the content in append mode.getOutputStream
(int bufferSize) Returns an output stream for writing the content.Returns an input/output stream to use to read and write the content of the file in a random manner.long
getSize()
Returns the size of the content (in bytes).boolean
hasAttribute
(String attrName) Checks if an attribute exists.boolean
isOpen()
Checks if an input and/or output stream is open.boolean
Checks if an input or output stream is open.void
removeAttribute
(String attrName) Removes an attribute.void
Used internally to flag situations where the file attributes should be retrieved again.void
setAttribute
(String attrName, Object value) Sets the value of an attribute.void
setLastModifiedTime
(long modTime) Sets the last-modified timestamp.long
write
(OutputStream output) Writes this content to an OutputStream.long
write
(OutputStream output, int bufferSize) Writes this content to an OutputStream.long
write
(FileContent fileContent) Writes this content to another FileContent.long
write
(FileObject file) Writes this content to another FileObject.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.vfs2.FileContent
getByteArray, getString, getString, isEmpty
-
Constructor Details
-
DefaultFileContent
public DefaultFileContent(AbstractFileObject fileObject, FileContentInfoFactory fileContentInfoFactory) Constructs a new instance.- Parameters:
fileObject
- The file object.fileContentInfoFactory
- The info factory.
-
-
Method Details
-
close
Closes all resources used by the content, including all streams, readers and writers.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFileContent
- Throws:
FileSystemException
- if an error occurs.
-
getAttribute
Gets the value of an attribute.- Specified by:
getAttribute
in interfaceFileContent
- Parameters:
attrName
- The attribute name.- Returns:
- The value of the attribute or null.
- Throws:
FileSystemException
- if an error occurs.
-
getAttributeNames
Lists the attributes of this file.- Specified by:
getAttributeNames
in interfaceFileContent
- Returns:
- An array of attribute names.
- Throws:
FileSystemException
- if an error occurs.
-
getAttributes
Returns a read-only map of this file's attributes.- Specified by:
getAttributes
in interfaceFileContent
- Returns:
- a Map of the file's attributes.
- Throws:
FileSystemException
- if an error occurs.
-
getCertificates
Returns the certificates used to sign this file.- Specified by:
getCertificates
in interfaceFileContent
- Returns:
- An array of Certificates.
- Throws:
FileSystemException
- if an error occurs.
-
getContentInfo
Gets the FileContentInfo which describes the content-type, content-encoding.- Specified by:
getContentInfo
in interfaceFileContent
- Returns:
- The FileContentInfo.
- Throws:
FileSystemException
- if an error occurs.
-
getFile
Returns the file that this is the content of.- Specified by:
getFile
in interfaceFileContent
- Returns:
- the FileObject.
-
getInputStream
Returns an input stream for reading the content.- Specified by:
getInputStream
in interfaceFileContent
- Returns:
- The InputStream
- Throws:
FileSystemException
- if an error occurs.
-
getInputStream
Returns an input stream for reading the content.- Specified by:
getInputStream
in interfaceFileContent
- Parameters:
bufferSize
- The buffer size to use.- Returns:
- The InputStream
- Throws:
FileSystemException
- if an error occurs.- Since:
- 2.4
-
getLastModifiedTime
Returns the last-modified timestamp.- Specified by:
getLastModifiedTime
in interfaceFileContent
- Returns:
- The last modified timestamp.
- Throws:
FileSystemException
- if an error occurs.
-
getOutputStream
Returns an output stream for writing the content.- Specified by:
getOutputStream
in interfaceFileContent
- Returns:
- The OutputStream for the file.
- Throws:
FileSystemException
- if an error occurs.
-
getOutputStream
Returns an output stream for writing the content in append mode.- Specified by:
getOutputStream
in interfaceFileContent
- Parameters:
bAppend
- true if the data written should be appended.- Returns:
- The OutputStream for the file.
- Throws:
FileSystemException
- if an error occurs.
-
getOutputStream
Returns an output stream for writing the content in append mode.- Specified by:
getOutputStream
in interfaceFileContent
- Parameters:
bAppend
- true if the data written should be appended.bufferSize
- The buffer size to use.- Returns:
- The OutputStream for the file.
- Throws:
FileSystemException
- if an error occurs.- Since:
- 2.4
-
getOutputStream
Returns an output stream for writing the content.- Specified by:
getOutputStream
in interfaceFileContent
- Parameters:
bufferSize
- The buffer size to use.- Returns:
- The OutputStream for the file.
- Throws:
FileSystemException
- if an error occurs.- Since:
- 2.4
-
getRandomAccessContent
Returns an input/output stream to use to read and write the content of the file in a random manner.- Specified by:
getRandomAccessContent
in interfaceFileContent
- Parameters:
mode
- The RandomAccessMode.- Returns:
- A RandomAccessContent object to access the file.
- Throws:
FileSystemException
- if an error occurs.
-
getSize
Returns the size of the content (in bytes).- Specified by:
getSize
in interfaceFileContent
- Returns:
- The size of the content (in bytes).
- Throws:
FileSystemException
- if an error occurs.
-
hasAttribute
Checks if an attribute exists.- Specified by:
hasAttribute
in interfaceFileContent
- Parameters:
attrName
- The name of the attribute to check.- Returns:
- true if the attribute is associated with the file.
- Throws:
FileSystemException
- if an error occurs.- Since:
- 2.0
-
isOpen
Checks if an 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
Checks if an input or output stream is open. This checks all threads.- Returns:
- true if this is the case
-
removeAttribute
Removes an attribute.- Specified by:
removeAttribute
in interfaceFileContent
- Parameters:
attrName
- The name of the attribute to remove.- Throws:
FileSystemException
- if an error occurs.- Since:
- 2.0
-
resetAttributes
Used internally to flag situations where the file attributes should be retrieved again.- Since:
- 2.0
-
setAttribute
Sets the value of an attribute.- Specified by:
setAttribute
in interfaceFileContent
- Parameters:
attrName
- The name of the attribute to add.value
- The value of the attribute.- Throws:
FileSystemException
- if an error occurs.
-
setLastModifiedTime
Sets the last-modified timestamp.- Specified by:
setLastModifiedTime
in interfaceFileContent
- Parameters:
modTime
- The last modified timestamp.- Throws:
FileSystemException
- if an error occurs.
-
write
Writes this content to another FileContent.- Specified by:
write
in interfaceFileContent
- Parameters:
fileContent
- The target FileContent.- Returns:
- the total number of bytes written
- Throws:
IOException
- if an error occurs writing the content.- Since:
- 2.1
-
write
Writes this content to another FileObject.- Specified by:
write
in interfaceFileContent
- Parameters:
file
- The target FileObject.- Returns:
- the total number of bytes written
- Throws:
IOException
- if an error occurs writing the content.- Since:
- 2.1
-
write
Writes this content to an OutputStream.- Specified by:
write
in interfaceFileContent
- Parameters:
output
- The target OutputStream.- Returns:
- the total number of bytes written
- Throws:
IOException
- if an error occurs writing the content.- Since:
- 2.1
-
write
Writes this content to an OutputStream.- Specified by:
write
in interfaceFileContent
- Parameters:
output
- The target OutputStream.bufferSize
- The buffer size to write data chunks.- Returns:
- the total number of bytes written
- Throws:
IOException
- if an error occurs writing the file.- Since:
- 2.1
-