org.modeshape.jcr.value.binary
Class SharedLockingInputStream
java.lang.Object
java.io.InputStream
org.modeshape.jcr.value.binary.SharedLockingInputStream
- All Implemented Interfaces:
- Closeable
public final class SharedLockingInputStream
- extends InputStream
A InputStream
implementation around a file that creates a shared lock when reading the file, ensuring the file is not
changed by other writers in this or other JVM processes. The stream automatically closes itself and releases the lock when
closed explicitly
or if there are any errors or exceptions while reading. Caution: be very careful when
working with this class, as any open without close operations can produce "readLocks" which do not get released, blocking any
potential subsequent writes.
key
protected final BinaryKey key
file
protected final File file
lockManager
protected final NamedLocks lockManager
stream
protected InputStream stream
processLock
protected Lock processLock
fileLock
protected FileLocks.WrappedLock fileLock
eofReached
protected boolean eofReached
SharedLockingInputStream
public SharedLockingInputStream(BinaryKey key,
File file,
NamedLocks lockManager)
- Create a self-closing, (shared) locking
InputStream
to read the content of the supplied file
.
- Parameters:
key
- the binary key; may not be nullfile
- the file that is to be read; may not be nulllockManager
- the manager of the locks, from which a read lock is to be obtained; may be null if no read lock is
needed
open
protected void open()
throws IOException
- Throws:
IOException
available
public int available()
throws IOException
- Overrides:
available
in class InputStream
- Throws:
IOException
close
public void close()
throws IOException
- Specified by:
close
in interface Closeable
- Overrides:
close
in class InputStream
- Throws:
IOException
equals
public boolean equals(Object obj)
- Overrides:
equals
in class Object
hashCode
public int hashCode()
- Overrides:
hashCode
in class Object
mark
public void mark(int readlimit)
- Overrides:
mark
in class InputStream
markSupported
public boolean markSupported()
- Overrides:
markSupported
in class InputStream
read
public int read(byte[] b,
int off,
int len)
throws IOException
- Overrides:
read
in class InputStream
- Throws:
IOException
read
public int read(byte[] b)
throws IOException
- Overrides:
read
in class InputStream
- Throws:
IOException
read
public int read()
throws IOException
- Specified by:
read
in class InputStream
- Throws:
IOException
reset
public void reset()
throws IOException
- Overrides:
reset
in class InputStream
- Throws:
IOException
skip
public long skip(long n)
throws IOException
- Overrides:
skip
in class InputStream
- Throws:
IOException
toString
public String toString()
- Overrides:
toString
in class Object
Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.