|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.entityfs.util.base.AbstractWritableFile
org.entityfs.util.ByteArrayWritableFile
public class ByteArrayWritableFile
This is a write only WritableFile
implementation that store
everything that is written to a byte array. The data written to this file can
be retrieved by calling toByteArray()
.
Locking instances of this class returns a NoObjectDummyLock
, so
instances of this class are not thread safe.
Constructor Summary | |
---|---|
ByteArrayWritableFile()
Create a byte array backed writable file with the default initial capacity ( FileSystemBuilder.DEFAULT_BUFFER_SIZE bytes). |
|
ByteArrayWritableFile(int capacity)
Create a byte array backed writable file with the provided initial capacity. |
Method Summary | |
---|---|
OutputStream |
openForAppend()
Open the file for appending. |
OutputStream |
openForWrite()
Opens the file for writing. |
byte[] |
toByteArray()
Get the data written to the file as a byte array. |
Methods inherited from class org.entityfs.util.base.AbstractWritableFile |
---|
getWriteLock, isWriteLockedByCurrentThread, lockForWriting, openChannelForAppend, openChannelForWrite |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ByteArrayWritableFile()
FileSystemBuilder.DEFAULT_BUFFER_SIZE
bytes).
public ByteArrayWritableFile(int capacity)
capacity
- The initial capacity, in bytes.Method Detail |
---|
public OutputStream openForWrite()
WritableFile
WritableFile.openForAppend()
to append to the file.
The caller is responsible for closing the stream.
When two output streams, one writing and one appending are open on the same file, the stream opened for write will ignore the contents written by the other stream and the content written by the other stream will be overwritten. When two or more appending streams are opened on a file, a stream will not overwrite the content written by the other streams.
Although a write lock on the file is required for the execution thread
opening the stream, the stream itself is not protected from access by
other threads. It can be protected by wrapping it in a
LockAwareOutputStream
.
OutputStream
to write to. The stream must be closed by
the caller.WritableFile.openForAppend()
,
WritableFile.openChannelForWrite()
public OutputStream openForAppend()
WritableFile
WritableFile.openForWrite()
to delete the previous contents before
writing. This requires that the file supports the
FCAppendable
capability (and/or that the
file system supports the FSCAppendableFiles
capability.
The caller is responsible for closing the stream.
When two appending output streams are open on the same file, one stream will not overwrite contents written by the other stream. Compare this with the behavior of one writing and one appending stream.
Although a write lock on the file is required for the execution thread
opening the stream, the stream itself is not protected from access by
other threads. It can be protected by wrapping it in a
LockAwareWritableByteChannel
.
OutputStream
to write to. The stream must be closed by
the caller.WritableFile.openForWrite()
,
WritableFile.openChannelForAppend()
public byte[] toByteArray()
byte
array.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |