org.entityfs.util
Class UrlReadableFile

java.lang.Object
  extended by org.entityfs.util.base.AbstractReadableFile
      extended by org.entityfs.util.UrlReadableFile
All Implemented Interfaces:
Lockable, ReadLockable, Named, NamedReadableFile, ReadableFile

public class UrlReadableFile
extends AbstractReadableFile
implements NamedReadableFile

This is a ReadableFile that encapsulates an URL.

Locking instances of this class returns a NoObjectDummyLock.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
UrlReadableFile(URL url)
           
 
Method Summary
 String getName()
          Get the name.
 long getSize()
          Get the size of the file (in bytes).
 InputStream openForRead()
          Open this file for reading.
 
Methods inherited from class org.entityfs.util.base.AbstractReadableFile
getDataSize, getReadLock, isReadLockedByCurrentThread, lockForReading, openChannelForRead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.entityfs.ReadableFile
getDataSize, openChannelForRead
 
Methods inherited from interface org.entityfs.lock.ReadLockable
getReadLock, isReadLockedByCurrentThread, lockForReading
 

Constructor Detail

UrlReadableFile

public UrlReadableFile(URL url)
Method Detail

getName

public String getName()
Description copied from interface: Named
Get the name. The name of the root directory is /.

Specified by:
getName in interface Named
Returns:
The name of the named object.

openForRead

public InputStream openForRead()
                        throws WrappedIOException
Open this file for reading.

Specified by:
openForRead in interface ReadableFile
Returns:
An InputStream on the file. The stream must be closed by the caller.
Throws:
WrappedIOException - If the underlying URL throws an IOException.

getSize

public long getSize()
Description copied from interface: ReadableFile
Get the size of the file (in bytes). This is the number of bytes that the file occupies where it is stored.

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.

Specified by:
getSize in interface ReadableFile
Returns:
The size of the file, in bytes.
See Also:
ReadableFile.getDataSize()