com.bbn.swede.core.dom
Class UnparseableFilterRandomAccessFile

java.lang.Object
  extended byjava.io.RandomAccessFile
      extended bycom.bbn.swede.core.dom.UnparseableFilterRandomAccessFile
All Implemented Interfaces:
DataInput, DataOutput

public class UnparseableFilterRandomAccessFile
extends RandomAccessFile

A wrapper for a java.io.RandomAccessFile that blanks out portions of the file. Given a list of text regions to ignore, it performs exactly the same as an ordinary RandomAccessFile, except that all text in the specified regions is replaced with spaces. This allows parsers to easily work around portions of the text that are known to be invalid.


Field Summary
protected  List _lInvalidRegions
          A list of IRegions to blank out when reading from the file.
 
Constructor Summary
UnparseableFilterRandomAccessFile(File file, String mode, IRegion[] regions)
          Creates a new UnparseableFilterRandomAccessFile.
 
Method Summary
protected  IRegion findContainingRegion(long offset)
          Checks the list of blank-out regions for one containing a specific offset .
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 int readUnfiltered()
          Reads a character from the file at the current seek position, ignoring the blank-out regions .
 int readUnfiltered(byte[] b)
          Reads up to b.length bytes from this file into an array of bytes, ignoring the blank-out regions.
 int readUnfiltered(byte[] b, int off, int len)
          Reads up to len bytes from this file into an array of bytes, ignoring the blank-out regions.
 
Methods inherited from class java.io.RandomAccessFile
close, getChannel, getFD, getFilePointer, length, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_lInvalidRegions

protected List _lInvalidRegions
A list of IRegions to blank out when reading from the file.

Constructor Detail

UnparseableFilterRandomAccessFile

public UnparseableFilterRandomAccessFile(File file,
                                         String mode,
                                         IRegion[] regions)
                                  throws FileNotFoundException
Creates a new UnparseableFilterRandomAccessFile.

Parameters:
file - The file object
mode - The file mode.
regions - Array of regions to blank out
Throws:
FileNotFoundException - if file cannot be opened for random access.
See Also:
java.io.RandomAccessFile#mode
Method Detail

findContainingRegion

protected IRegion findContainingRegion(long offset)
Checks the list of blank-out regions for one containing a specific offset .

Parameters:
offset - The offset to locate
Returns:
The blank-out region containing the offset, or null if it does not fall in a blank-out region

read

public int read()
         throws IOException
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Throws:
IOException

readUnfiltered

public int readUnfiltered()
                   throws IOException
Reads a character from the file at the current seek position, ignoring the blank-out regions .

Returns:
The character read from the file
Throws:
IOException - if a read error occurs.

readUnfiltered

public int readUnfiltered(byte[] b,
                          int off,
                          int len)
                   throws IOException
Reads up to len bytes from this file into an array of bytes, ignoring the blank-out regions.

Parameters:
b - The buffer into which data is read
off - The start offset of the data
len - The maximum number of bytes to read
Returns:
The number of bytes read, or -1 if there is no more data because EOF has been reached
Throws:
IOException - if a read error occurs.

readUnfiltered

public int readUnfiltered(byte[] b)
                   throws IOException
Reads up to b.length bytes from this file into an array of bytes, ignoring the blank-out regions.

Parameters:
b - The buffer into which data is read
Returns:
The number of bytes read, or -1 if there is no more data because EOF has been reached
Throws:
IOException - if a read error occurs.


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.