public interface FileContent extends Closeable
To read from a file, use the InputStream
returned by getInputStream()
.
To write to a file, use the OutputStream
returned by getOutputStream()
method. This will create
the file, and the parent folder, if necessary.
A file may have multiple InputStreams open at the same time.
FileObject.getContent()
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes all resources used by the content, including any open stream.
|
Object |
getAttribute(String attrName)
Gets the value of an attribute of the file's content.
|
String[] |
getAttributeNames()
Lists the attributes of the file's content.
|
Map<String,Object> |
getAttributes()
Returns a read-only map of this file's attributes.
|
Certificate[] |
getCertificates()
Retrieves the certificates if any used to sign this file or folder.
|
FileContentInfo |
getContentInfo()
get the content info.
|
FileObject |
getFile()
Returns the file which this is the content of.
|
InputStream |
getInputStream()
Returns an input stream for reading the file's content.
|
long |
getLastModifiedTime()
Determines the last-modified timestamp of the file.
|
OutputStream |
getOutputStream()
Returns an output stream for writing the file's content.
|
OutputStream |
getOutputStream(boolean bAppend)
Returns an output stream for writing the file's content.
|
RandomAccessContent |
getRandomAccessContent(RandomAccessMode mode)
Returns an stream for reading/writing the file's content.
|
long |
getSize()
Determines the size of the file, in bytes.
|
boolean |
hasAttribute(String attrName)
Checks if an attribute of the file's content exists.
|
boolean |
isOpen()
check if this file has open streams.
|
void |
removeAttribute(String attrName)
Removes the value of an attribute of the file's content.
|
void |
setAttribute(String attrName,
Object value)
Sets the value of an attribute of the file's content.
|
void |
setLastModifiedTime(long modTime)
Sets the last-modified timestamp of the file.
|
long |
write(FileContent output)
Writes this content to another FileContent.
|
long |
write(FileObject file)
Writes this content to another FileObject.
|
long |
write(OutputStream output)
Writes this content to an OutputStream.
|
long |
write(OutputStream output,
int bufferSize)
Writes this content to an OutputStream.
|
FileObject getFile()
long getSize() throws FileSystemException
FileSystemException
- If the file does not exist, or is being written to, or on error
determining the size.long getLastModifiedTime() throws FileSystemException
FileSystemException
- If the file does not exist, or is being written to, or on error
determining the last-modified timestamp.void setLastModifiedTime(long modTime) throws FileSystemException
modTime
- The time to set the last-modified timestamp to.FileSystemException
- If the file is read-only, or is being written to, or on error
setting the last-modified timestamp.boolean hasAttribute(String attrName) throws FileSystemException
attrName
- The name of the attribute.FileSystemException
- If the file does not exist, or does not support
attributes.Map<String,Object> getAttributes() throws FileSystemException
FileSystemException
- If the file does not exist, or does not support attributes.String[] getAttributeNames() throws FileSystemException
FileSystemException
- If the file does not exist, or does not support attributes.Object getAttribute(String attrName) throws FileSystemException
attrName
- The name of the attribute. Attribute names are case insensitive.FileSystemException
- If the file does not exist, or does not support attributes.void setAttribute(String attrName, Object value) throws FileSystemException
attrName
- The name of the attribute.value
- The value of the attribute.FileSystemException
- If the file does not exist, or is read-only, or does not support
attributes, or on error setting the attribute.void removeAttribute(String attrName) throws FileSystemException
attrName
- The name of the attribute.FileSystemException
- If the file does not exist, or is read-only, or does not support
attributes, or on error removing the attribute.Certificate[] getCertificates() throws FileSystemException
FileSystemException
- If the file does not exist, or is being written.InputStream getInputStream() throws FileSystemException
There may only be a single input or output stream open for the file at any time.
BufferedInputStream
.FileSystemException
- If the file does not exist, or is being read, or is being written,
or on error opening the stream.OutputStream getOutputStream() throws FileSystemException
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.
BufferedOutputStream
.FileSystemException
- If the file is read-only, or is being read, or is being written,
or on error opening the stream.RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
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.
mode
- The mode to use to access the file.FileSystemException
- If the file is read-only, or is being read, or is being written,
or on error opening the stream.OutputStream getOutputStream(boolean bAppend) throws FileSystemException
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.
bAppend
- true if you would like to append to the file.
This may not be supported by all implementations.BufferedOutputStream
.FileSystemException
- If the file is read-only, or is being read, or is being written,
or bAppend is true and the implementation does not support it,
or on error opening the stream.void close() throws FileSystemException
This method is a hint to the implementation that it can release resources. This object can continue to be used after calling this method.
close
in interface AutoCloseable
close
in interface Closeable
FileSystemException
- if an error occurs closing the file.FileContentInfo getContentInfo() throws FileSystemException
FileSystemException
- if an error occurs.boolean isOpen()
long write(FileContent output) throws IOException
output
- The target OutputStream.IOException
- if an error occurs writing the content.long write(FileObject file) throws IOException
file
- The target FileObject.IOException
- if an error occurs writing the content.long write(OutputStream output) throws IOException
output
- The target OutputStream.IOException
- if an error occurs writing the content.long write(OutputStream output, int bufferSize) throws IOException
output
- The target OutputStream.bufferSize
- The buffer size to write data chunks.IOException
- if an error occurs writing the file.Copyright © 2002–2016. All rights reserved.