public final class DefaultFileContent extends java.lang.Object implements FileContent
Modifier and Type | Class and Description |
---|---|
private class |
DefaultFileContent.FileContentInputStream
An input stream for reading content.
|
(package private) class |
DefaultFileContent.FileContentOutputStream
An output stream for writing content.
|
private class |
DefaultFileContent.FileRandomAccessContent
An input/output stream for reading/writing content on random positions
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
attrs |
private FileContentInfo |
fileContentInfo |
private FileContentInfoFactory |
fileContentInfoFactory |
private AbstractFileObject |
fileObject |
private int |
openStreams
Counts open streams for this file.
|
private boolean |
resetAttributes |
private java.util.Map<java.lang.String,java.lang.Object> |
roAttrs |
(package private) static int |
STATE_CLOSED |
(package private) static int |
STATE_OPENED |
private java.lang.ThreadLocal<FileContentThreadData> |
threadLocal |
private static int |
WRITE_BUFFER_SIZE
The default buffer size for
write(OutputStream) |
Constructor and Description |
---|
DefaultFileContent(AbstractFileObject file,
FileContentInfoFactory fileContentInfoFactory) |
Modifier and Type | Method and Description |
---|---|
private java.io.InputStream |
buildInputStream(int bufferSize) |
private java.io.OutputStream |
buildOutputStream(boolean bAppend,
int bufferSize) |
void |
close()
Closes all resources used by the content, including all streams, readers and writers.
|
private void |
endInput(DefaultFileContent.FileContentInputStream instr)
Handles the end of input stream.
|
private void |
endOutput()
Handles the end of output stream.
|
private void |
endRandomAccess(RandomAccessContent rac)
Handles the end of random access.
|
java.lang.Object |
getAttribute(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.
|
FileContentInfo |
getContentInfo()
Gets the FileContentInfo which describes the content-type, content-encoding
|
FileObject |
getFile()
Returns the file that this is the content of.
|
java.io.InputStream |
getInputStream()
Returns an input stream for reading the content.
|
java.io.InputStream |
getInputStream(int bufferSize)
Returns an input stream for reading the content.
|
long |
getLastModifiedTime()
Returns the last-modified timestamp.
|
private FileContentThreadData |
getOrCreateThreadData() |
java.io.OutputStream |
getOutputStream()
Returns an output stream for writing the content.
|
java.io.OutputStream |
getOutputStream(boolean bAppend)
Returns an output stream for writing the content in append mode.
|
java.io.OutputStream |
getOutputStream(boolean bAppend,
int bufferSize)
Returns an output stream for writing the content in append mode.
|
java.io.OutputStream |
getOutputStream(int bufferSize)
Returns an output stream for writing the content.
|
RandomAccessContent |
getRandomAccessContent(RandomAccessMode mode)
Returns an input/output stream to use to read and write the content of the file in an random manner.
|
long |
getSize()
Returns the size of the content (in bytes).
|
boolean |
hasAttribute(java.lang.String attrName)
Checks if an attribute exists.
|
boolean |
isOpen()
Checks if a input and/or output stream is open.
|
boolean |
isOpenGlobal()
Checks if an input or output stream is open.
|
void |
removeAttribute(java.lang.String attrName)
Removes an attribute.
|
void |
resetAttributes()
Used internally to flag situations where the file attributes should be reretrieved.
|
void |
setAttribute(java.lang.String attrName,
java.lang.Object value)
Sets the value of an attribute.
|
void |
setLastModifiedTime(long modTime)
Sets the last-modified timestamp.
|
(package private) void |
streamClosed() |
(package private) void |
streamOpened() |
long |
write(FileContent fileContent)
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getByteArray, getString, getString
static final int STATE_CLOSED
static final int STATE_OPENED
private static final int WRITE_BUFFER_SIZE
write(OutputStream)
private final AbstractFileObject fileObject
private java.util.Map<java.lang.String,java.lang.Object> attrs
private java.util.Map<java.lang.String,java.lang.Object> roAttrs
private FileContentInfo fileContentInfo
private final FileContentInfoFactory fileContentInfoFactory
private final java.lang.ThreadLocal<FileContentThreadData> threadLocal
private boolean resetAttributes
private int openStreams
public DefaultFileContent(AbstractFileObject file, FileContentInfoFactory fileContentInfoFactory)
private FileContentThreadData getOrCreateThreadData()
void streamOpened()
void streamClosed()
public FileObject getFile()
getFile
in interface FileContent
public long getSize() throws FileSystemException
getSize
in interface FileContent
FileSystemException
- if an error occurs.public long getLastModifiedTime() throws FileSystemException
getLastModifiedTime
in interface FileContent
FileSystemException
- if an error occurs.public void setLastModifiedTime(long modTime) throws FileSystemException
setLastModifiedTime
in interface FileContent
modTime
- The last modified timestamp.FileSystemException
- if an error occurs.public boolean hasAttribute(java.lang.String attrName) throws FileSystemException
hasAttribute
in interface FileContent
attrName
- The name of the attribute to check.FileSystemException
- if an error occurs.public java.util.Map<java.lang.String,java.lang.Object> getAttributes() throws FileSystemException
getAttributes
in interface FileContent
FileSystemException
- if an error occurs.public void resetAttributes()
public java.lang.String[] getAttributeNames() throws FileSystemException
getAttributeNames
in interface FileContent
FileSystemException
- if an error occurs.public java.lang.Object getAttribute(java.lang.String attrName) throws FileSystemException
getAttribute
in interface FileContent
attrName
- The attribute name.FileSystemException
- if an error occurs.public void setAttribute(java.lang.String attrName, java.lang.Object value) throws FileSystemException
setAttribute
in interface FileContent
attrName
- The name of the attribute to add.value
- The value of the attribute.FileSystemException
- if an error occurs.public void removeAttribute(java.lang.String attrName) throws FileSystemException
removeAttribute
in interface FileContent
attrName
- The name of the attribute to remove.FileSystemException
- if an error occurs.public java.security.cert.Certificate[] getCertificates() throws FileSystemException
getCertificates
in interface FileContent
FileSystemException
- if an error occurs.public java.io.InputStream getInputStream() throws FileSystemException
getInputStream
in interface FileContent
FileSystemException
- if an error occurs.public java.io.InputStream getInputStream(int bufferSize) throws FileSystemException
getInputStream
in interface FileContent
bufferSize
- The buffer size to use.FileSystemException
- if an error occurs.public RandomAccessContent getRandomAccessContent(RandomAccessMode mode) throws FileSystemException
getRandomAccessContent
in interface FileContent
mode
- The RandomAccessMode.FileSystemException
- if an error occurs.public java.io.OutputStream getOutputStream() throws FileSystemException
getOutputStream
in interface FileContent
FileSystemException
- if an error occurs.public java.io.OutputStream getOutputStream(boolean bAppend) throws FileSystemException
getOutputStream
in interface FileContent
bAppend
- true if the data written should be appended.FileSystemException
- if an error occurs.public java.io.OutputStream getOutputStream(int bufferSize) throws FileSystemException
getOutputStream
in interface FileContent
bufferSize
- The buffer size to use.FileSystemException
- if an error occurs.public java.io.OutputStream getOutputStream(boolean bAppend, int bufferSize) throws FileSystemException
getOutputStream
in interface FileContent
bAppend
- true if the data written should be appended.bufferSize
- The buffer size to use.FileSystemException
- if an error occurs.public void close() throws FileSystemException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface FileContent
FileSystemException
- if an error occurs.private java.io.InputStream buildInputStream(int bufferSize) throws FileSystemException
FileSystemException
private java.io.OutputStream buildOutputStream(boolean bAppend, int bufferSize) throws FileSystemException
FileSystemException
private void endInput(DefaultFileContent.FileContentInputStream instr)
private void endRandomAccess(RandomAccessContent rac)
private void endOutput() throws java.lang.Exception
java.lang.Exception
public boolean isOpen()
This checks only the scope of the current thread.
isOpen
in interface FileContent
public boolean isOpenGlobal()
public FileContentInfo getContentInfo() throws FileSystemException
getContentInfo
in interface FileContent
FileSystemException
- if an error occurs.public long write(FileContent fileContent) throws java.io.IOException
write
in interface FileContent
fileContent
- The target FileContent.java.io.IOException
- if an error occurs writing the content.public long write(FileObject file) throws java.io.IOException
write
in interface FileContent
file
- The target FileObject.java.io.IOException
- if an error occurs writing the content.public long write(java.io.OutputStream output) throws java.io.IOException
write
in interface FileContent
output
- The target OutputStream.java.io.IOException
- if an error occurs writing the content.public long write(java.io.OutputStream output, int bufferSize) throws java.io.IOException
write
in interface FileContent
output
- The target OutputStream.bufferSize
- The buffer size to write data chunks.java.io.IOException
- if an error occurs writing the file.