Package org.apache.commons.vfs2.provider
Class DefaultFileContent
- java.lang.Object
-
- org.apache.commons.vfs2.provider.DefaultFileContent
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,FileContent
public final class DefaultFileContent extends java.lang.Object implements FileContent
The content of a file.
-
-
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.Map<java.lang.String,java.lang.Object>getAttributes()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).booleanhasAttribute(java.lang.String attrName)Checks if an attribute exists.booleanisOpen()Check if a input and/or output stream is open.booleanisOpenGlobal()Check if a input and/or output stream is open.voidremoveAttribute(java.lang.String attrName)Removes an attribute.voidresetAttributes()Used internally to flag situations where the file attributes should be reretrieved.voidsetAttribute(java.lang.String attrName, java.lang.Object value)Sets the value of an attribute.voidsetLastModifiedTime(long modTime)Sets the last-modified timestamp.longwrite(java.io.OutputStream output)Writes this content to an OutputStream.longwrite(java.io.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.
-
-
-
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- Returns:
- the FileObject.
-
getSize
public long getSize() throws FileSystemExceptionReturns 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
public long getLastModifiedTime() throws FileSystemExceptionReturns the last-modified timestamp.- Specified by:
getLastModifiedTimein interfaceFileContent- Returns:
- The last modified timestamp.
- Throws:
FileSystemException- if an error occurs.
-
setLastModifiedTime
public void setLastModifiedTime(long modTime) throws FileSystemExceptionSets the last-modified timestamp.- Specified by:
setLastModifiedTimein interfaceFileContent- Parameters:
modTime- The last modified timestamp.- Throws:
FileSystemException- if an error occurs.
-
hasAttribute
public boolean hasAttribute(java.lang.String attrName) throws FileSystemExceptionChecks 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
public java.util.Map<java.lang.String,java.lang.Object> getAttributes() throws FileSystemExceptionReturns 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
public java.lang.String[] getAttributeNames() throws FileSystemExceptionLists the attributes of this file.- Specified by:
getAttributeNamesin interfaceFileContent- Returns:
- An array of attribute names.
- Throws:
FileSystemException- if an error occurs.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String attrName) throws FileSystemExceptionGets 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
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 to add.value- The value of the attribute.- Throws:
FileSystemException- if an error occurs.
-
removeAttribute
public void removeAttribute(java.lang.String attrName) throws FileSystemExceptionRemoves 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
public java.security.cert.Certificate[] getCertificates() throws FileSystemExceptionReturns the certificates used to sign this file.- Specified by:
getCertificatesin interfaceFileContent- Returns:
- An array of Certificates.
- Throws:
FileSystemException- if an error occurs.
-
getInputStream
public java.io.InputStream getInputStream() throws FileSystemExceptionReturns an input stream for reading the content.- Specified by:
getInputStreamin interfaceFileContent- Returns:
- The InputStream
- Throws:
FileSystemException- if an error occurs.
-
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- Parameters:
mode- The RandomAccessMode.- Returns:
- A RandomAccessContent object to access the file.
- Throws:
FileSystemException- if an error occurs.
-
getOutputStream
public java.io.OutputStream getOutputStream() throws FileSystemExceptionReturns an output stream for writing the content.- Specified by:
getOutputStreamin interfaceFileContent- Returns:
- The OutputStream for the file.
- Throws:
FileSystemException- if an error occurs.
-
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 the data written should be appended.- Returns:
- The OutputStream for the file.
- Throws:
FileSystemException- if an error occurs.
-
close
public void close() throws FileSystemExceptionCloses all resources used by the content, including all streams, readers and writers.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceFileContent- Throws:
FileSystemException- if an error occurs.
-
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- Returns:
- The FileContentInfo.
- Throws:
FileSystemException- if an error occurs.
-
write
public long write(FileContent fileContent) throws java.io.IOException
Writes this content to another FileContent.- Specified by:
writein interfaceFileContent- Parameters:
fileContent- The target FileContent.- Returns:
- the total number of bytes written
- Throws:
java.io.IOException- if an error occurs writing the content.- Since:
- 2.1
-
write
public long write(FileObject file) throws java.io.IOException
Writes this content to another FileObject.- Specified by:
writein interfaceFileContent- Parameters:
file- The target FileObject.- Returns:
- the total number of bytes written
- Throws:
java.io.IOException- if an error occurs writing the content.- Since:
- 2.1
-
write
public long write(java.io.OutputStream output) throws java.io.IOExceptionWrites this content to an OutputStream.- Specified by:
writein interfaceFileContent- Parameters:
output- The target OutputStream.- Returns:
- the total number of bytes written
- Throws:
java.io.IOException- if an error occurs writing the content.- Since:
- 2.1
-
write
public long write(java.io.OutputStream output, int bufferSize) throws java.io.IOExceptionWrites 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:
java.io.IOException- if an error occurs writing the file.- Since:
- 2.1
-
-