Class DefaultFileContent
java.lang.Object
org.apache.commons.vfs2.provider.DefaultFileContent
- All Implemented Interfaces:
Closeable, AutoCloseable, FileContent
The content of a file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classAn input stream for reading content.(package private) final classAn output stream for writing content.private final classAn input/output stream for reading/writing content on random positionsprivate final classAn input stream for reading content. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Certificate[]private FileContentInfoprivate final FileContentInfoFactoryprivate final AbstractFileObject<?> private intCounts open streams for this file.private boolean(package private) static final int(package private) static final intprivate final ThreadLocal<FileContentThreadData> private static final intThe default buffer size forwrite(OutputStream) -
Constructor Summary
ConstructorsConstructorDescriptionDefaultFileContent(AbstractFileObject file, FileContentInfoFactory fileContentInfoFactory) -
Method Summary
Modifier and TypeMethodDescriptionprivate InputStreambuildInputStream(int bufferSize) private OutputStreambuildOutputStream(boolean bAppend, int bufferSize) voidclose()Closes all resources used by the content, including all streams, readers and writers.private voidendInput(InputStream instr) Handles the end of input stream.private voidHandles the end of output stream.private voidHandles the end of random access.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-encodinggetFile()Returns the file that this is the content of.private FileContentThreadDataReturns an input stream for reading the content.getInputStream(int bufferSize) Returns an input stream for reading the content.longReturns 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 an random manner.longgetSize()Returns the size of the content (in bytes).booleanhasAttribute(String attrName) Checks if an attribute exists.booleanisOpen()Checks if a input and/or output stream is open.booleanChecks if an input or output stream is open.voidremoveAttribute(String attrName) Removes an attribute.voidUsed internally to flag situations where the file attributes should be reretrieved.voidsetAttribute(String attrName, Object value) Sets the value of an attribute.voidsetLastModifiedTime(long modTime) Sets the last-modified timestamp.(package private) void(package private) voidlongwrite(OutputStream output) Writes this content to an OutputStream.longwrite(OutputStream output, int bufferSize) Writes this content to an OutputStream.longwrite(FileContent fileContent) Writes this content to another FileContent.longwrite(FileObject file) Writes this content to another FileObject.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface FileContent
getByteArray, getString, getString, isEmpty
-
Field Details
-
EMPTY_CERTIFICATE_ARRAY
-
STATE_CLOSED
static final int STATE_CLOSED- See Also:
-
STATE_OPENED
static final int STATE_OPENED- See Also:
-
WRITE_BUFFER_SIZE
private static final int WRITE_BUFFER_SIZEThe default buffer size forwrite(OutputStream)- See Also:
-
fileObject
-
attrs
-
roAttrs
-
fileContentInfo
-
fileContentInfoFactory
-
threadLocal
-
resetAttributes
private boolean resetAttributes -
openStreams
private int openStreamsCounts open streams for this file.
-
-
Constructor Details
-
DefaultFileContent
-
-
Method Details
-
getFileContentThreadData
-
streamOpened
void streamOpened() -
streamClosed
void streamClosed() -
getFile
Returns the file that this is the content of.- Specified by:
getFilein interfaceFileContent- Returns:
- the FileObject.
-
getSize
Returns the size of the content (in bytes).- Specified by:
getSizein interfaceFileContent- Returns:
- The size of the content (in bytes).
- Throws:
FileSystemException- if an error occurs.
-
getLastModifiedTime
Returns the last-modified timestamp.- Specified by:
getLastModifiedTimein interfaceFileContent- Returns:
- The last modified timestamp.
- Throws:
FileSystemException- if an error occurs.
-
setLastModifiedTime
Sets the last-modified timestamp.- Specified by:
setLastModifiedTimein interfaceFileContent- Parameters:
modTime- The last modified timestamp.- Throws:
FileSystemException- if an error occurs.
-
hasAttribute
Checks if an attribute exists.- Specified by:
hasAttributein 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
-
getAttributes
Returns a read-only map of this file's attributes.- Specified by:
getAttributesin interfaceFileContent- Returns:
- a Map of the file's attributes.
- Throws:
FileSystemException- if an error occurs.
-
resetAttributes
public void resetAttributes()Used internally to flag situations where the file attributes should be reretrieved.- Since:
- 2.0
-
getAttributeNames
Lists the attributes of this file.- Specified by:
getAttributeNamesin interfaceFileContent- Returns:
- An array of attribute names.
- Throws:
FileSystemException- if an error occurs.
-
getAttribute
Gets the value of an attribute.- Specified by:
getAttributein interfaceFileContent- Parameters:
attrName- The attribute name.- Returns:
- The value of the attribute or null.
- Throws:
FileSystemException- if an error occurs.
-
setAttribute
Sets the value of an attribute.- Specified by:
setAttributein interfaceFileContent- Parameters:
attrName- The name of the attribute to add.value- The value of the attribute.- Throws:
FileSystemException- if an error occurs.
-
removeAttribute
Removes an attribute.- Specified by:
removeAttributein interfaceFileContent- Parameters:
attrName- The name of the attribute to remove.- Throws:
FileSystemException- if an error occurs.- Since:
- 2.0
-
getCertificates
Returns the certificates used to sign this file.- Specified by:
getCertificatesin interfaceFileContent- Returns:
- An array of Certificates.
- Throws:
FileSystemException- if an error occurs.
-
getInputStream
Returns an input stream for reading the content.- Specified by:
getInputStreamin interfaceFileContent- Returns:
- The InputStream
- Throws:
FileSystemException- if an error occurs.
-
getInputStream
Returns an input stream for reading the content.- Specified by:
getInputStreamin interfaceFileContent- Parameters:
bufferSize- The buffer size to use.- Returns:
- The InputStream
- 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 an random manner.- Specified by:
getRandomAccessContentin interfaceFileContent- Parameters:
mode- The RandomAccessMode.- Returns:
- A RandomAccessContent object to access the file.
- Throws:
FileSystemException- if an error occurs.
-
getOutputStream
Returns an output stream for writing the content.- Specified by:
getOutputStreamin 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:
getOutputStreamin 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.- Specified by:
getOutputStreamin interfaceFileContent- Parameters:
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 in append mode.- Specified by:
getOutputStreamin 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
-
close
Closes all resources used by the content, including all streams, readers and writers.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceFileContent- Throws:
FileSystemException- if an error occurs.
-
buildInputStream
- Throws:
FileSystemException
-
buildOutputStream
- Throws:
FileSystemException
-
endInput
Handles the end of input stream. -
endRandomAccess
Handles the end of random access. -
endOutput
-
isOpen
public boolean isOpen()Checks 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()Checks if an input or output stream is open. This checks all threads.- Returns:
- true if this is the case
-
getContentInfo
Gets the FileContentInfo which describes the content-type, content-encoding- Specified by:
getContentInfoin interfaceFileContent- Returns:
- The FileContentInfo.
- Throws:
FileSystemException- if an error occurs.
-
write
Writes this content to another FileContent.- Specified by:
writein 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:
writein 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:
writein 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:
writein 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
-