TrueZIP 6.8.2

de.schlichtherle.io.rof
Class FilterReadOnlyFile

java.lang.Object
  extended by de.schlichtherle.io.rof.AbstractReadOnlyFile
      extended by de.schlichtherle.io.rof.FilterReadOnlyFile
All Implemented Interfaces:
ReadOnlyFile
Direct Known Subclasses:
BufferedReadOnlyFile, CipherReadOnlyFile, CountingReadOnlyFile

public class FilterReadOnlyFile
extends AbstractReadOnlyFile

A base class for any class which wants to decorate a ReadOnlyFile.

Note that subclasses of this class often 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 their file pointers a'la:

     ReadOnlyFile rof = new SimpleReadOnlyFile(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 underlying ReadOnlyFile again after you have finished working with an instance of this class, you should synchronize their file pointers using the pattern as described in FilterReadOnlyFile.

Version:
$Id: FilterReadOnlyFile.java 06f3ba684701 2010/11/04 01:15:55 christian $
Author:
Christian Schlichtherle

Field Summary
protected  ReadOnlyFile rof
          The read only file to be filtered.
 
Constructor Summary
FilterReadOnlyFile(ReadOnlyFile rof)
          Creates a new instance of FilterReadOnlyFile, which filters the given read only file.
 
Method Summary
 void close()
           
 long getFilePointer()
           
 long length()
           
 int read()
           
 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 file pointer offset, measured from the beginning of this file, at which the next read occurs.
 
Methods inherited from class de.schlichtherle.io.rof.AbstractReadOnlyFile
read, readFully, readFully, skipBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rof

protected ReadOnlyFile rof
The read only file to be filtered.

Constructor Detail

FilterReadOnlyFile

public FilterReadOnlyFile(ReadOnlyFile rof)
Creates a new instance of FilterReadOnlyFile, which filters the given read only file.

Method Detail

length

public long length()
            throws IOException
Throws:
IOException

getFilePointer

public long getFilePointer()
                    throws IOException
Throws:
IOException

seek

public void seek(long pos)
          throws IOException
Description copied from interface: ReadOnlyFile
Sets the file pointer offset, measured from the beginning of this file, at which the next read occurs. Whether the offset may be set beyond the end of the file is up to the implementor. For example, the SimpleReadOnlyFile subclasses RandomAccessFile and passes "r" as a parameter to the superclass constructor. On the Windows platform, this implementation allows to seek past the end of file, but on the Linux platform it doesn't.

Parameters:
pos - The offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Throws:
IOException - If pos is less than 0 or if an I/O error occurs.

read

public int read()
         throws IOException
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Description copied from interface: ReadOnlyFile
Reads up to len bytes of data from this read only file into the given array. This method blocks until at least one byte of input is available.

Parameters:
b - The buffer to fill with data.
off - The start offset of the data.
len - The maximum number of bytes to read.
Returns:
The total number of bytes read, or -1 if there is no more data because the end of the file has been reached.
Throws:
IOException - On any I/O related issue.

close

public void close()
           throws IOException
Throws:
IOException

TrueZIP 6.8.2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.