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()
Gets the attributes of the file's content.
|
Map<String,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.
|
Certificate[] |
getCertificates()
Gets the certificates if any used to sign this file or folder.
|
FileContentInfo |
getContentInfo()
Gets the content info.
|
FileObject |
getFile()
Gets the file which this is the content of.
|
InputStream |
getInputStream()
Gets an input stream for reading the file's content.
|
default InputStream |
getInputStream(int bufferSize)
Gets an input stream for reading the file's content.
|
long |
getLastModifiedTime()
Gets the last-modified timestamp of the file.
|
OutputStream |
getOutputStream()
Gets an output stream for writing the file's content.
|
OutputStream |
getOutputStream(boolean bAppend)
Gets an output stream for writing the file's content.
|
default OutputStream |
getOutputStream(boolean bAppend,
int bufferSize)
Gets an output stream for writing the file's content.
|
default OutputStream |
getOutputStream(int bufferSize)
Gets an output stream for writing the file's content.
|
RandomAccessContent |
getRandomAccessContent(RandomAccessMode mode)
Gets an stream for reading/writing the file's content.
|
long |
getSize()
Gets the size of the file, in bytes.
|
default String |
getString(Charset charset)
Returns the content of a file as a String.
|
default String |
getString(String charset)
Gets the content of a file as a String.
|
boolean |
hasAttribute(String attrName)
Checks if an attribute of the file's content exists.
|
default boolean |
isEmpty()
Checks if the receiver is empty.
|
boolean |
isOpen()
Checks 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.
|
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.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.String[] getAttributeNames() throws FileSystemException
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.default byte[] getByteArray() throws IOException
IOException
- if the file content cannot be accessed.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()
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 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.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.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 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 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 String getString(Charset charset) throws IOException
charset
- The file character set, may be null.IOException
- if the file content cannot be accessed.default String getString(String charset) throws IOException
charset
- The file character set, may be null.IOException
- if the file content cannot be accessed.boolean hasAttribute(String attrName) throws FileSystemException
attrName
- The name of the attribute.FileSystemException
- If the file does not exist, or does not support attributes.default boolean isEmpty() throws FileSystemException
FileSystemException
- If the file does not exist, or is being written to, or on error determining the size.boolean isOpen()
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.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 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 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–2020 The Apache Software Foundation. All rights reserved.