|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ReadableFile
This interface is implemented by objects that behave as readable files,
EFile
:s for instance.
Use this interface instead of EFile
wherever possible to make mocking
and testing easier.
WritableFile
,
RandomlyAccessibleFile
Method Summary | |
---|---|
long |
getDataSize()
Get the size of the data in the file. |
long |
getSize()
Get the size of the file (in bytes). |
ReadableByteChannel |
openChannelForRead()
Open a ReadableByteChannel for reading from the file. |
InputStream |
openForRead()
Opens the file for reading. |
Methods inherited from interface org.entityfs.lock.ReadLockable |
---|
getReadLock, isReadLockedByCurrentThread, lockForReading |
Method Detail |
---|
InputStream openForRead() throws ReadLockRequiredException, AccessDeniedException
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
.
InputStream
on the file. The stream must be closed by
the caller.
ReadLockRequiredException
- If the client does not have a read lock
for the file.
AccessDeniedException
- If the client does not have read access to
the file.ReadableByteChannel openChannelForRead() throws ReadLockRequiredException, AccessDeniedException
ReadableByteChannel
for reading from the file. The
semantics of this method is the same as for 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
.
ReadableByteChannel
. The channel must be closed
by the caller. The channel may be a
ScatteringByteChannel
, but that is not
required.
ReadLockRequiredException
- If the client does not have a read lock
for the file.
AccessDeniedException
- If the client does not have read access to
the file.openForRead()
long getSize() throws ReadLockRequiredException, AccessDeniedException
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.
ReadLockRequiredException
- If the client does not have a read lock
for the file.
AccessDeniedException
- If the client does not have read access to
the file.getDataSize()
long getDataSize() throws ReadLockRequiredException, AccessDeniedException
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.
ReadLockRequiredException
- If the client does not have a read lock
for the file.
AccessDeniedException
- If the client does not have read access to
the file.getSize()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |