|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.entityfs.impl.FileDelegateReadWritableFileAdapter
public class FileDelegateReadWritableFileAdapter
This is an adapter object that turns a FileDelegate
into a
ReadWritableFile
.
This object does not do any locking. All locks returned are
NoObjectDummyLock
:s.
Constructor Summary | |
---|---|
FileDelegateReadWritableFileAdapter(FileDelegate fd)
|
Method Summary | |
---|---|
long |
copy(OutputStream os)
Dump the file contents to the stream. |
long |
copy(WritableByteChannel oc)
Copy the file's contents to the WritableByteChannel . |
void |
delete()
Delete the entity from the file system. |
long |
getDataSize()
Get the size of the data in the file. |
EntityLock |
getReadLock()
This method returns a NoObjectDummyLock . |
long |
getSize()
Get the size of the file (in bytes). |
long |
getSizeNoLocking()
Get an approximate size of the file without having to lock it. |
EntityLock |
getWriteLock()
This method returns a NoObjectDummyLock . |
boolean |
isDeleted()
Check if the entity has been deleted. |
boolean |
isReadLockedByCurrentThread()
This method always returns true . |
boolean |
isWriteLockedByCurrentThread()
This method always returns true . |
EntityLock |
lockForReading()
This method returns a NoObjectDummyLock . |
EntityLock |
lockForWriting()
This method returns a NoObjectDummyLock . |
WritableByteChannel |
openChannelForAppend()
Open a WritableByteChannel for appending to the file. |
ReadableByteChannel |
openChannelForRead()
Open a ReadableByteChannel for reading from the file. |
WritableByteChannel |
openChannelForWrite()
Open a WritableByteChannel for writing on the file. |
OutputStream |
openForAppend()
Open the file for appending. |
RandomAccess |
openForRandomAccess(RandomAccessMode mode)
Open the file for random access in the specified mode. |
InputStream |
openForRead()
Opens the file for reading. |
OutputStream |
openForWrite()
Opens the file for writing. |
void |
replaceContents(ReadWritableFile f)
Replace the contents of this file with the contents of the supplied file and then delete the supplied file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FileDelegateReadWritableFileAdapter(FileDelegate fd)
Method Detail |
---|
public EntityLock getReadLock()
NoObjectDummyLock
.
getReadLock
in interface ReadLockable
public EntityLock lockForReading()
NoObjectDummyLock
.
lockForReading
in interface ReadLockable
public EntityLock getWriteLock()
NoObjectDummyLock
.
getWriteLock
in interface WriteLockable
public EntityLock lockForWriting()
NoObjectDummyLock
.
lockForWriting
in interface WriteLockable
public boolean isReadLockedByCurrentThread()
true
. Override it to change that
behavior.
isReadLockedByCurrentThread
in interface ReadLockable
true
if the lockable object is read or write locked by
the current thread.public boolean isWriteLockedByCurrentThread()
true
. Override it to change that
behavior.
isWriteLockedByCurrentThread
in interface WriteLockable
true
if the lockable object is write locked by the
current thread.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
.
openForAppend
in interface WritableFile
OutputStream
to write to. The stream must be closed by
the caller.WritableFile.openForWrite()
,
WritableFile.openChannelForAppend()
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
.
openForWrite
in interface WritableFile
OutputStream
to write to. The stream must be closed by
the caller.WritableFile.openForAppend()
,
WritableFile.openChannelForWrite()
public InputStream openForRead()
ReadableFile
Although a read 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
LockAwareInputStream
.
openForRead
in interface ReadableFile
InputStream
on the file. The stream must be closed by
the caller.public WritableByteChannel openChannelForWrite()
WritableFile
WritableByteChannel
for writing on the file. The semantics
of this method is the same as for WritableFile.openForWrite()
.
openChannelForWrite
in interface WritableFile
WritableByteChannel
. The channel must be closed
by the caller. The returned channel may be a
GatheringByteChannel
, but that is not required.WritableFile.openForWrite()
,
WritableFile.openChannelForAppend()
public WritableByteChannel openChannelForAppend()
WritableFile
WritableByteChannel
for appending to the file. The
semantics of this method is the same as for WritableFile.openForAppend()
.
openChannelForAppend
in interface WritableFile
WritableByteChannel
. The channel must be closed
by the caller. The returned channel may be a
GatheringByteChannel
, but that is not required.public ReadableByteChannel openChannelForRead()
ReadableFile
ReadableByteChannel
for reading from the file. The
semantics of this method is the same as for ReadableFile.openForRead()
.
Although a read lock on the file is required for the execution thread
opening the channel, the channel itself is not protected from access by
other threads. It can be protected by wrapping it in a
LockAwareReadableByteChannel
.
openChannelForRead
in interface ReadableFile
ReadableByteChannel
. The channel must be closed
by the caller. The channel may be a
ScatteringByteChannel
, but that is not
required.ReadableFile.openForRead()
public RandomAccess openForRandomAccess(RandomAccessMode mode)
RandomlyAccessibleFile
Although a read or write lock on the file is required for the execution
thread opening the RandomAccess
, the RandomAccess
object
itself is not protected from access by other threads. It can be protected
by wrapping it in a LockAwareRandomAccess
object.
openForRandomAccess
in interface RandomlyAccessibleFile
mode
- The mode to open the file in.
RandomAccess
object. It must be closed by the
caller.public void delete()
Deletable
EntityView.isValid()
will return false
from now on).
delete
in interface Deletable
public boolean isDeleted()
Deletable
EntityView.isValid()
, this method does not do any backend validation, so if the entity has
been deleted in the backend storage without going through the EntityFS
API, use that method instead.
isDeleted
in interface Deletable
true
if the entity object has been deleted.public long getSize()
ReadableFile
Note: Most, but not all, implementations know their sizes. If an implementation does not know its size beforehand, this method will be slow since it has to calculate the file size when it is called.
Implementation note: If the size of the backing file is not known,
the
StreamUtil.getSizeOfDataInStream(InputStream, int)
method can be used to calculate it.
getSize
in interface ReadableFile
ReadableFile.getDataSize()
public long getSizeNoLocking()
ReadWritableFile
getSizeNoLocking
in interface ReadWritableFile
0
is returned.ReadableFile.getSize()
public long getDataSize()
ReadableFile
ReadableFile.getSize()
.
Warning: Calculating the data size of a file has the potential of being really slow, depending on the implementation used. The entire file may have to be read through in order to calculate the size of its data.
Implementation note: If the size of the backing file is not known,
the
StreamUtil.getSizeOfDataInStream(InputStream, int)
method can be used to calculate it.
getDataSize
in interface ReadableFile
ReadableFile.getSize()
public void replaceContents(ReadWritableFile f)
ReadWritableFile
f
over to this file, which makes the entire operation quick and not
requiring any extra disk space.
If both files support metadata, this file's metadata is replaced with
that of f
.
replaceContents
in interface ReadWritableFile
f
- The file whose contents are to be moved to this file. f
is deleted by this method.public long copy(OutputStream os)
ReadWritableFile
copy
in interface ReadWritableFile
os
- The stream the file contents are written to. The stream is not
closed after writing, that must be done by the caller.
public long copy(WritableByteChannel oc)
ReadWritableFile
WritableByteChannel
.
copy
in interface ReadWritableFile
oc
- The WritableByteChannel
. The channel is not closed by
this method.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |