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
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public void mark(int readlimit)
mark
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public int read(byte[] b) throws IOException
read
in class InputStream
IOException
public int read() throws IOException
read
in class InputStream
IOException
public void reset() throws IOException
reset
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.