org.entityfs.util.io
Class LockAwareFileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FileInputStream
          extended by org.entityfs.util.io.LockAwareFileInputStream
All Implemented Interfaces:
Closeable

public class LockAwareFileInputStream
extends FileInputStream

This is a FileInputStream that keeps a reference to the read lock of the open EFile. It is required that the lock is held by the calling thread when it is calling any of the methods on instances of this class. When the stream is closed, the lock is unlocked if it is still locked.

FileDescriptor:s and FileChannel:s from this class are not lock-aware.

Instances of this class are not thread safe.

Since:
1.0
Author:
Karl Gustafsson
See Also:
LockAwareFileInputStreamFactoryImpl
In_jar:
entityfs-core

Constructor Summary
LockAwareFileInputStream(FileDescriptor fd, EntityLock l)
           
LockAwareFileInputStream(File f, EntityLock l)
           
LockAwareFileInputStream(String name, EntityLock l)
           
 
Method Summary
 int available()
           
 void close()
          This will unlock the write lock if it is still locked by the current thread.
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 long skip(long n)
           
 
Methods inherited from class java.io.FileInputStream
finalize, getChannel, getFD
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockAwareFileInputStream

public LockAwareFileInputStream(File f,
                                EntityLock l)
                         throws FileNotFoundException
Throws:
FileNotFoundException

LockAwareFileInputStream

public LockAwareFileInputStream(FileDescriptor fd,
                                EntityLock l)

LockAwareFileInputStream

public LockAwareFileInputStream(String name,
                                EntityLock l)
                         throws FileNotFoundException
Throws:
FileNotFoundException
Method Detail

close

public void close()
           throws IOException
This will unlock the write lock if it is still locked by the current thread.

Specified by:
close in interface Closeable
Overrides:
close in class FileInputStream
Throws:
IOException

available

public int available()
              throws IOException
Overrides:
available in class FileInputStream
Throws:
IOException

read

public int read()
         throws IOException
Overrides:
read in class FileInputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class FileInputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class FileInputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class FileInputStream
Throws:
IOException