Package org.apache.commons.vfs
Interface FileContent
-
- All Known Implementing Classes:
DefaultFileContent
public interface FileContentRepresents the data content of a file.To read from a file, use the
InputStreamreturned bygetInputStream().To write to a file, use the
OutputStreamreturned bygetOutputStream()method. This will create the file, and the parent folder, if necessary.A file may have multiple InputStreams open at the sametime.
- Version:
- $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Wed, 29 Nov 2006) $
- Author:
- Adam Murdoch
- See Also:
FileObject.getContent()
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Closes all resources used by the content, including any open stream.java.lang.ObjectgetAttribute(java.lang.String attrName)Gets the value of an attribute of the file's content.java.lang.String[]getAttributeNames()Lists the attributes of the file's content.java.util.MapgetAttributes()Returns a read-only map of this file's attributes.java.security.cert.Certificate[]getCertificates()Retrieves the certificates if any used to sign this file or folder.FileContentInfogetContentInfo()get the content info.FileObjectgetFile()Returns the file which this is the content of.java.io.InputStreamgetInputStream()Returns an input stream for reading the file's content.longgetLastModifiedTime()Determines the last-modified timestamp of the file.java.io.OutputStreamgetOutputStream()Returns an output stream for writing the file's content.java.io.OutputStreamgetOutputStream(boolean bAppend)Returns an output stream for writing the file's content.RandomAccessContentgetRandomAccessContent(RandomAccessMode mode)Returns an stream for reading/writing the file's content.longgetSize()Determines the size of the file, in bytes.booleanisOpen()check if this file has open streamsvoidsetAttribute(java.lang.String attrName, java.lang.Object value)Sets the value of an attribute of the file's content.voidsetLastModifiedTime(long modTime)Sets the last-modified timestamp of the file.
-
-
-
Method Detail
-
getFile
FileObject getFile()
Returns the file which this is the content of.
-
getSize
long getSize() throws FileSystemExceptionDetermines the size of the file, in bytes.- 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
long getLastModifiedTime() throws FileSystemExceptionDetermines the last-modified timestamp of the file.- 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
void setLastModifiedTime(long modTime) throws FileSystemExceptionSets the last-modified timestamp of the file. Creates the file if it does not exist.- 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
java.util.Map getAttributes() throws FileSystemExceptionReturns a read-only map of this file's attributes.- Throws:
FileSystemException- If the file does not exist, or does not support attributes.
-
getAttributeNames
java.lang.String[] getAttributeNames() throws FileSystemExceptionLists the attributes of the file's content.- Returns:
- The names of the attributes. Never returns null;
- Throws:
FileSystemException- If the file does not exist, or does not support attributes.
-
getAttribute
java.lang.Object getAttribute(java.lang.String attrName) throws FileSystemExceptionGets the value of an attribute of the file's content.- 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
void setAttribute(java.lang.String attrName, java.lang.Object value) throws FileSystemExceptionSets the value of an attribute of the file's content. Creates the file if it does not exist.- 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
java.security.cert.Certificate[] getCertificates() throws FileSystemExceptionRetrieves the certificates if any used to sign this file or folder.- 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
java.io.InputStream getInputStream() throws FileSystemExceptionReturns an input stream for reading the file's content.There may only be a single input or output stream open for the file at any time.
- 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.
-
getOutputStream
java.io.OutputStream getOutputStream() throws FileSystemExceptionReturns an output stream for writing the file's content. If the file does not exist, this method creates it, and the parent folder, if necessary. If the file does exist, it is replaced with whatever is written to the output stream.There may only be a single input or output stream open for the file at any time.
- 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.
-
getRandomAccessContent
RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
Returns an stream for reading/writing the file's content. If the file does not exist, and you use one of the write* methods, this method creates it, and the parent folder, if necessary. If the file does exist, parts of the file are replaced with whatever is written at a given position.There may only be a single input or output stream open for the file at any time.
- Throws:
FileSystemException- If the file is read-only, or is being read, or is being written, or on error opening the stream.
-
getOutputStream
java.io.OutputStream getOutputStream(boolean bAppend) throws FileSystemExceptionReturns an output stream for writing the file's content. If the file does not exist, this method creates it, and the parent folder, if necessary. If the file does exist, it is replaced with whatever is written to the output stream.There may only be a single input or output stream open for the file at any time.
- 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
void close() throws FileSystemExceptionCloses all resources used by the content, including any open stream. Commits pending changes to the file.This method is a hint to the implementation that it can release resources. This object can continue to be used after calling this method.
- Throws:
FileSystemException
-
getContentInfo
FileContentInfo getContentInfo() throws FileSystemException
get the content info. e.g. type, encoding, ...- Throws:
FileSystemException
-
isOpen
boolean isOpen()
check if this file has open streams
-
-