|
TrueZIP Kernel 7.0-rc2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.schlichtherle.truezip.rof.AbstractReadOnlyFile
de.schlichtherle.truezip.rof.DecoratingReadOnlyFile
@ThreadSafe @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public abstract class DecoratingReadOnlyFile
An abstract decorator for a read only file.
Note that subclasses of this class may implement their own virtual file
pointer.
Thus, if you would like to access the underlying ReadOnlyFile
again after you have finished working with the
FilteredReadOnlyFile, you should synchronize its file pointer like
this:
ReadOnlyFile rof = new DefaultReadOnlyFile(new File("HelloWorld.java"));
try {
ReadOnlyFile frof = new FilteredReadOnlyFile(rof);
try {
// Do any file input on brof here...
frof.seek(1);
} finally {
// Synchronize the file pointers.
rof.seek(frof.getFilePointer());
}
// This assertion would fail if we hadn't done the file pointer
// synchronization!
assert rof.getFilePointer() == 1;
} finally {
rof.close();
}
This does not apply to this base class, however.
Subclasses implemententing their own virtual file pointer should add a note referring to this classes Javadoc like this:
Note: This class implements its own virtual file pointer. Thus, if you would like to access the underlyingReadOnlyFileagain after you have finished working with an instance of this class, you should synchronize their file pointers using the pattern as described inDecoratingReadOnlyFile.
| Field Summary | |
|---|---|
protected ReadOnlyFile |
delegate
The nullable decorated read only file. |
| Constructor Summary | |
|---|---|
protected |
DecoratingReadOnlyFile(ReadOnlyFile rof)
Creates a new instance of DecoratingReadOnlyFile,
which filters the given read only file. |
| Method Summary | |
|---|---|
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. |
String |
toString()
Returns a string representation of this object for debugging and logging purposes. |
| Methods inherited from class de.schlichtherle.truezip.rof.AbstractReadOnlyFile |
|---|
read, readFully, readFully |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
@Nullable protected ReadOnlyFile delegate
| Constructor Detail |
|---|
protected DecoratingReadOnlyFile(@CheckForNull
ReadOnlyFile rof)
DecoratingReadOnlyFile,
which filters the given read only file.
| Method Detail |
|---|
public long length()
throws IOException
ReadOnlyFile
IOException
public long getFilePointer()
throws IOException
ReadOnlyFile
IOException
public void seek(long pos)
throws 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.
pos - The current byte position as a zero-based index.
IOException - If pos is less than 0 or if
an I/O error occurs.
public int read()
throws IOException
ReadOnlyFile
IOException
public int read(byte[] b,
int off,
int len)
throws 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.
b - 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.
IOException - On any I/O related issue.
public void close()
throws IOException
ReadOnlyFile
IOExceptionpublic String toString()
toString in class Object
|
TrueZIP Kernel 7.0-rc2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||