@ThreadSafe public class SynchronizedReadOnlyFile extends DecoratingReadOnlyFile
ReadOnlyFile
via an object provided to its constructor.| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Object |
lock
The object to synchronize on - never
null. |
delegate| Constructor and Description |
|---|
SynchronizedReadOnlyFile(ReadOnlyFile rof)
Constructs a new synchronized read only file.
|
SynchronizedReadOnlyFile(ReadOnlyFile rof,
java.lang.Object lock)
Constructs a new synchronized read only file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this read-only file and releases any non-heap resources
allocated for it.
|
long |
getFilePointer()
Returns the current byte position in the file as a zero-based index.
|
long |
length()
Returns the length of the file in bytes.
|
int |
read()
Reads and returns the next byte or -1 if the end of the file has been
reached.
|
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from this read only file into
the given array. |
void |
seek(long pos)
Sets the current byte position in the file as a zero-based index at
which the next read occurs.
|
toStringread, readFully, readFullypublic SynchronizedReadOnlyFile(ReadOnlyFile rof)
rof - the read only file to wrap in this decorator.public SynchronizedReadOnlyFile(ReadOnlyFile rof, java.lang.Object lock)
rof - the input stream to wrap in this decorator.lock - the object to synchronize on.
If null, then this object is used, not the stream.public long length()
throws java.io.IOException
ReadOnlyFilelength in interface ReadOnlyFilelength in class DecoratingReadOnlyFilejava.io.IOExceptionpublic long getFilePointer()
throws java.io.IOException
ReadOnlyFilegetFilePointer in interface ReadOnlyFilegetFilePointer in class DecoratingReadOnlyFilejava.io.IOExceptionpublic void seek(long pos)
throws java.io.IOException
ReadOnlyFileDefaultReadOnlyFile subclass
RandomAccessFile passes "r" as a parameter to
the superclass constructor.
With Sun's JSE implementation, on the Windows platform this
implementation allows to seek past the end of file, but on the Linux
platform it doesn't.seek in interface ReadOnlyFileseek in class DecoratingReadOnlyFilepos - The current byte position as a zero-based index.java.io.IOException - If pos is less than 0 or if
an I/O error occurs.public int read()
throws java.io.IOException
ReadOnlyFileread in interface ReadOnlyFileread in class DecoratingReadOnlyFilejava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
ReadOnlyFilelen bytes of data from this read only file into
the given array.
This method blocks until at least one byte of input is available.read in interface ReadOnlyFileread in class DecoratingReadOnlyFileb - The buffer to fill with data.off - The start offset of the data.len - The maximum number of bytes to read.-1 if there is
no more data because the end of the file has been reached.java.io.IOException - On any I/O related issue.public void close()
throws java.io.IOException
ReadOnlyFileclose in interface ReadOnlyFileclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class DecoratingReadOnlyFilejava.io.IOExceptionCopyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.