public final class SharedLockingInputStream extends InputStream
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.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
eofReached |
protected File |
file |
protected FileLocks.WrappedLock |
fileLock |
protected BinaryKey |
key |
protected NamedLocks |
lockManager |
protected Lock |
processLock |
protected InputStream |
stream |
| Constructor and Description |
|---|
SharedLockingInputStream(BinaryKey key,
File file,
NamedLocks lockManager)
Create a self-closing, (shared) locking
InputStream to read the content of the supplied file. |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
boolean |
equals(Object obj) |
int |
hashCode() |
void |
mark(int readlimit) |
boolean |
markSupported() |
protected void |
open() |
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
String |
toString() |
protected final BinaryKey key
protected final File file
protected final NamedLocks lockManager
protected InputStream stream
protected Lock processLock
protected FileLocks.WrappedLock fileLock
protected boolean eofReached
public SharedLockingInputStream(BinaryKey key, File file, NamedLocks lockManager)
InputStream to read the content of the supplied file.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
neededprotected void open()
throws IOException
IOExceptionpublic int available()
throws IOException
available in class InputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic void mark(int readlimit)
mark in class InputStreampublic boolean markSupported()
markSupported in class InputStreampublic int read(byte[] b,
int off,
int len)
throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b)
throws IOException
read in class InputStreamIOExceptionpublic int read()
throws IOException
read in class InputStreamIOExceptionpublic void reset()
throws IOException
reset in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
skip in class InputStreamIOExceptionCopyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.