|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.entityfs.util.NamedReadableFileAdapter
public class NamedReadableFileAdapter
This adapter is used to give a ReadableFile a name, making it a
NamedReadableFile. It can for instance be used to pretend that a
EFile entity has another name.
| Constructor Summary | |
|---|---|
NamedReadableFileAdapter(ReadableFile f,
String name)
|
|
| Method Summary | |
|---|---|
long |
getDataSize()
Get the size of the data in the file. |
String |
getName()
Get the name. |
EntityLock |
getReadLock()
Get the read lock without locking it. |
long |
getSize()
Get the size of the file (in bytes). |
boolean |
isReadLockedByCurrentThread()
Does the calling thread hold a read lock for this object? A write lock also qualifies as a read lock. |
EntityLock |
lockForReading()
Lock object for reading and return the lock. |
ReadableByteChannel |
openChannelForRead()
Open a ReadableByteChannel for reading from the file. |
InputStream |
openForRead()
Opens the file for reading. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public NamedReadableFileAdapter(ReadableFile f,
String name)
| Method Detail |
|---|
public EntityLock getReadLock()
ReadLockableThis method always returns a lock, even if the object's file system is not locking or if the object is read only.
getReadLock in interface ReadLockablepublic EntityLock lockForReading()
ReadLockableEntityLockAdapterFactory and
LockAcquiringStrategy used. If this is called on an object that
somehow is connected to an entity object, that entity's file system's
entity lock adapter factory and lock acquiring strategy is used.
A read lock cannot be upgraded to a write lock (just like how Java's
ReadWriteLock works).
For more discussions on locks and locking, see Entity and
FileSystem.
This method always returns a lock, even if the object's file system is not locking or if the object is read only.
lockForReading in interface ReadLockablepublic boolean isReadLockedByCurrentThread()
ReadLockable
isReadLockedByCurrentThread in interface ReadLockabletrue if the lockable object is read or write locked by
the current thread.public String getName()
Named/.
getName in interface Namedpublic ReadableByteChannel openChannelForRead()
ReadableFileReadableByteChannel 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 ReadableFileReadableByteChannel. The channel must be closed
by the caller. The channel may be a
ScatteringByteChannel, but that is not
required.ReadableFile.openForRead()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 ReadableFileInputStream on the file. The stream must be closed by
the caller.
public long getDataSize()
throws ReadLockRequiredException,
AccessDeniedException
ReadableFileReadableFile.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 ReadableFileReadLockRequiredException - If the client does not have a read lock
for the file.
AccessDeniedException - If the client does not have read access to
the file.ReadableFile.getSize()
public long getSize()
throws ReadLockRequiredException,
AccessDeniedException
ReadableFileNote: 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 ReadableFileReadLockRequiredException - If the client does not have a read lock
for the file.
AccessDeniedException - If the client does not have read access to
the file.ReadableFile.getDataSize()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||