org.entityfs.util
Class FileReadableFile

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

public class FileReadableFile
extends AbstractReadableFile
implements NamedReadableFile

This is a ReadableFile that encapsulates a File.

The locking methods return a NoObjectDummyLock.

Since:
1.0
Author:
Karl Gustafsson
See Also:
FileWritableFile

Constructor Summary
FileReadableFile(File f)
           
 
Method Summary
 boolean equals(Object o)
           
 File getFile()
          Get the encapsulated File object.
 String getName()
          Get the name.
 long getSize()
          Get the size of the file (in bytes).
 int hashCode()
           
 FileChannel openChannelForRead()
          This opens a byte channel on the file.
 InputStream openForRead()
          Open this file for reading.
 String toString()
           
 
Methods inherited from class org.entityfs.util.base.AbstractReadableFile
getDataSize, getReadLock, isReadLockedByCurrentThread, lockForReading
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.entityfs.ReadableFile
getDataSize
 
Methods inherited from interface org.entityfs.lock.ReadLockable
getReadLock, isReadLockedByCurrentThread, lockForReading
 

Constructor Detail

FileReadableFile

public FileReadableFile(File f)
Method Detail

getFile

public File getFile()
Get the encapsulated File object.

Returns:
The File object.
Since:
1.1.4

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.

openChannelForRead

public FileChannel openChannelForRead()
                               throws WrappedIOException
This opens a byte channel on the file.

Specified by:
openChannelForRead in interface ReadableFile
Overrides:
openChannelForRead in class AbstractReadableFile
Returns:
An open byte channel.
Throws:
WrappedIOException
See Also:
ReadableFile.openForRead()

getSize

public long getSize()
             throws ReadLockRequiredException,
                    AccessDeniedException
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.
Throws:
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.
See Also:
ReadableFile.getDataSize()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object