public interface FileContent
extends java.io.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.
|
java.lang.Object |
getAttribute(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.Map<java.lang.String,java.lang.Object> |
getAttributes()
Returns a read-only map of this file's attributes.
|
default byte[] |
getByteArray()
Returns the content of a file as a byte array.
|
java.security.cert.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.
|
java.io.InputStream |
getInputStream()
Returns an input stream for reading the file's content.
|
default java.io.InputStream |
getInputStream(int bufferSize)
Returns an input stream for reading the file's content.
|
long |
getLastModifiedTime()
Determines the last-modified timestamp of the file.
|
java.io.OutputStream |
getOutputStream()
Returns an output stream for writing the file's content.
|
java.io.OutputStream |
getOutputStream(boolean bAppend)
Returns an output stream for writing the file's content.
|
default java.io.OutputStream |
getOutputStream(boolean bAppend,
int bufferSize)
Returns an output stream for writing the file's content.
|
default java.io.OutputStream |
getOutputStream(int bufferSize)
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.
|
default java.lang.String |
getString(java.nio.charset.Charset charset)
Returns the content of a file as a String.
|
default java.lang.String |
getString(java.lang.String charset)
Returns the content of a file as a String.
|
boolean |
hasAttribute(java.lang.String attrName)
Checks if an attribute of the file's content exists.
|
boolean |
isOpen()
check if this file has open streams.
|
void |
removeAttribute(java.lang.String attrName)
Removes the value of an attribute of the file's content.
|
void |
setAttribute(java.lang.String attrName,
java.lang.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(java.io.OutputStream output)
Writes this content to an OutputStream.
|
long |
write(java.io.OutputStream output,
int bufferSize)
Writes this content to an OutputStream.
|
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 java.lang.AutoCloseable
close
in interface java.io.Closeable
FileSystemException
- if an error occurs closing the file.java.lang.Object getAttribute(java.lang.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.java.lang.String[] getAttributeNames() throws FileSystemException
FileSystemException
- If the file does not exist, or does not support attributes.java.util.Map<java.lang.String,java.lang.Object> getAttributes() throws FileSystemException
FileSystemException
- If the file does not exist, or does not support attributes.java.security.cert.Certificate[] getCertificates() throws FileSystemException
FileSystemException
- If the file does not exist, or is being written.FileContentInfo getContentInfo() throws FileSystemException
FileSystemException
- if an error occurs.FileObject getFile()
java.io.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.default byte[] getByteArray() throws java.io.IOException
java.io.IOException
- if the file content cannot be accessed.default java.io.InputStream getInputStream(int bufferSize) throws FileSystemException
There may only be a single input or output stream open for the file at any time.
bufferSize
- The buffer size to use.BufferedInputStream
.FileSystemException
- If the file does not exist, or is being read, or is being written, or on error
opening the stream.long getLastModifiedTime() throws FileSystemException
FileSystemException
- If the file does not exist, or is being written to, or on error determining the
last-modified timestamp.java.io.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.java.io.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.default java.io.OutputStream getOutputStream(boolean bAppend, int bufferSize) 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.bufferSize
- The buffer size to use.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.default java.io.OutputStream getOutputStream(int bufferSize) 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.
bufferSize
- The buffer size to use.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.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.long getSize() throws FileSystemException
FileSystemException
- If the file does not exist, or is being written to, or on error determining the size.default java.lang.String getString(java.nio.charset.Charset charset) throws java.io.IOException
charset
- The file character set, may be null.java.io.IOException
- if the file content cannot be accessed.default java.lang.String getString(java.lang.String charset) throws java.io.IOException
charset
- The file character set, may be null.java.io.IOException
- if the file content cannot be accessed.boolean hasAttribute(java.lang.String attrName) throws FileSystemException
attrName
- The name of the attribute.FileSystemException
- If the file does not exist, or does not support attributes.boolean isOpen()
void removeAttribute(java.lang.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.void setAttribute(java.lang.String attrName, java.lang.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 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.long write(FileContent output) throws java.io.IOException
output
- The target OutputStream.java.io.IOException
- if an error occurs writing the content.long write(FileObject file) throws java.io.IOException
file
- The target FileObject.java.io.IOException
- if an error occurs writing the content.long write(java.io.OutputStream output) throws java.io.IOException
output
- The target OutputStream.java.io.IOException
- if an error occurs writing the content.long write(java.io.OutputStream output, int bufferSize) throws java.io.IOException
output
- The target OutputStream.bufferSize
- The buffer size to write data chunks.java.io.IOException
- if an error occurs writing the file.