|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.entityfs.util.ClasspathNamedReadableFile
public class ClasspathNamedReadableFile
This object can be used to treat a resource on the current classpath as a
NamedReadableFile
.
Constructor Summary | |
---|---|
ClasspathNamedReadableFile(AbsoluteLocation loc,
ClassLoader cl)
Create a named readable file using the resource at the specified location loaded by the supplied class loader. |
|
ClasspathNamedReadableFile(EntityLocation<?> loc,
Class<?> c)
Create a named readable file using the resource with the specified location. |
Method Summary | |
---|---|
long |
getDataSize()
Get the size of the data in the file. |
String |
getName()
Get the name. |
EntityLock |
getReadLock()
This method returns a dummy lock. |
long |
getSize()
Get the size of the file (in bytes). |
boolean |
isReadLockedByCurrentThread()
This method always returns true . |
EntityLock |
lockForReading()
This method returns a dummy 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 ClasspathNamedReadableFile(AbsoluteLocation loc, ClassLoader cl) throws EntityNotFoundException
To create the location, just substitute the '.
':s in the fully
qualified name for '/
':es in the AbsoluteLocation
.
cl
- The class loader to load the resource with.loc
- The fully qualified location of the resource.
EntityNotFoundException
- If there is no resource at the specified
location.public ClasspathNamedReadableFile(EntityLocation<?> loc, Class<?> c) throws EntityNotFoundException
To create the location, just substitute the '.
':s in the name for
'/
':es in the EntityLocation
.
The supplied class' class loader is used to load the resource.
c
- The class whose class loader will be used to load the resource.loc
- The location of the resource. This is either an
AbsoluteLocation
, meaning a fully qualified resource name, or a
RelativeLocation
taken relative to the supplied class' package's
location.
EntityNotFoundException
- If there is no resource at the specified
location.Method Detail |
---|
public ReadableByteChannel openChannelForRead() throws WrappedIOException
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.
WrappedIOException
ReadableFile.openForRead()
public InputStream openForRead() throws WrappedIOException
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.
WrappedIOException
public EntityLock getReadLock()
getReadLock
in interface ReadLockable
public boolean isReadLockedByCurrentThread()
true
.
isReadLockedByCurrentThread
in interface ReadLockable
true
, always.public EntityLock lockForReading()
lockForReading
in interface ReadLockable
public String getName() throws IllegalStateException, ReadLockRequiredException
Named
/
.
getName
in interface Named
IllegalStateException
- If this is called on a disconnected view.
ReadLockRequiredException
- If the client does not have a read lock
for the viewed entity or its parent.public long getDataSize() throws ReadLockRequiredException, AccessDeniedException
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
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.ReadableFile.getSize()
public long getSize() throws ReadLockRequiredException, AccessDeniedException
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
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.ReadableFile.getDataSize()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |