org.entityfs.util.io
Class LockAwareInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.entityfs.support.io.InputStreamProxy
          extended by org.entityfs.util.io.LockAwareInputStream
All Implemented Interfaces:
Closeable

public class LockAwareInputStream
extends InputStreamProxy

This is an InputStream 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.

Instances of this class are not thread safe.

Since:
1.0
Author:
Karl Gustafsson
See Also:
Files.openForRead(ReadableFile, EntityLock)

Constructor Summary
LockAwareInputStream(InputStream is, EntityLock lock)
           
 
Method Summary
 int available()
          This returns the number of bytes available in the proxied stream.
 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 org.entityfs.support.io.InputStreamProxy
getProxied, mark, markSupported, reset, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LockAwareInputStream

public LockAwareInputStream(InputStream is,
                            EntityLock lock)
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 InputStreamProxy
Throws:
IOException

available

public int available()
              throws IOException
Description copied from class: InputStreamProxy
This returns the number of bytes available in the proxied stream. Subclasses that do some kind of transformation on the data in the proxied stream will probably have to override this.

Overrides:
available in class InputStreamProxy
Throws:
IOException

read

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

read

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

read

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

skip

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