com.bbn.openmap.io
Interface InputReader

All Known Implementing Classes:
ByteArrayInputReader, FileInputReader, JarInputReader, StreamInputReader, URLInputReader

public interface InputReader

The InputReader is an interface that isolates the data file source type from the BinaryFile. Represents an InputStream setup, and basic read functions.


Method Summary
 long available()
          Return how many bytes left to be read in the file.
 void close()
          Closes the underlying file.
 long getFilePointer()
          Get the index of the next character to be read
 java.lang.String getName()
          Get the name of the source.
 long length()
          Return the total byte length of the source.
 int read()
          Read from the file.
 int read(byte[] b)
          Read from the file.
 int read(byte[] b, int off, int len)
          Read from the file
 byte[] readBytes(int howmany, boolean allowless)
          Read from the file.
 void seek(long pos)
          Set the index of the next character to be read.
 long skipBytes(long n)
          Skip over n bytes in the input file
 

Method Detail

getName

java.lang.String getName()
Get the name of the source.


skipBytes

long skipBytes(long n)
               throws java.io.IOException
Skip over n bytes in the input file

Parameters:
n - the number of bytes to skip
Returns:
the actual number of bytes skipped. annoying, isn't it?
Throws:
java.io.IOException - Any IO errors that occur in skipping bytes in the underlying file

getFilePointer

long getFilePointer()
                    throws java.io.IOException
Get the index of the next character to be read

Returns:
the index
Throws:
java.io.IOException - Any IO errors that occur in accessing the underlying file

seek

void seek(long pos)
          throws java.io.IOException
Set the index of the next character to be read.

Parameters:
pos - the position to seek to.
Throws:
java.io.IOException - Any IO Errors that occur in seeking the underlying file.

length

long length()
            throws java.io.IOException
Return the total byte length of the source. May not be accurate for StreamInputReaders.

Returns:
the number of bytes remaining to be read (counted in bytes)
Throws:
java.io.IOException - Any IO errors encountered in accessing the file

available

long available()
               throws java.io.IOException
Return how many bytes left to be read in the file.

Returns:
the number of bytes remaining to be read (counted in bytes)
Throws:
java.io.IOException - Any IO errors encountered in accessing the file

close

void close()
           throws java.io.IOException
Closes the underlying file.

Throws:
java.io.IOException - Any IO errors encountered in accessing the file

read

int read()
         throws java.io.IOException
Read from the file.

Returns:
one byte from the file. -1 for EOF
Throws:
java.io.IOException - Any IO errors encountered in reading from the file

read

int read(byte[] b,
         int off,
         int len)
         throws java.io.IOException
Read from the file

Parameters:
b - The byte array to read into
off - the first array position to read into
len - the number of bytes to read
Returns:
the number of bytes read
Throws:
java.io.IOException - Any IO errors encountered in reading from the file

read

int read(byte[] b)
         throws java.io.IOException
Read from the file.

Parameters:
b - the byte array to read into. Equivalent to read(b, 0, b.length)
Returns:
the number of bytes read
Throws:
java.io.IOException - Any IO errors encountered in reading from the file
See Also:
RandomAccessFile.read(byte[])

readBytes

byte[] readBytes(int howmany,
                 boolean allowless)
                 throws java.io.EOFException,
                        FormatException
Read from the file.

Parameters:
howmany - the number of bytes to read
allowless - if we can return fewer bytes than requested
Returns:
the array of bytes read.
Throws:
FormatException - Any IO Exceptions, plus an end-of-file encountered after reading some, but now enough, bytes when allowless was false
java.io.EOFException - Encountered an end-of-file while allowless was false, but NO bytes had been read.


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details