## com.bbn.openmap.io
Class BinaryBufferedFile

    java.lang.Object
      com.bbn.openmap.io.BinaryFile
          com.bbn.openmap.io.BinaryBufferedFile

public class BinaryBufferedFile
extends BinaryFile

This class extends the BinaryFile class, doing buffered reads on the underlying input file. The buffer size is not modifiable after construction, and the buffer management isn't the greatest.

Field Summary

Fields inherited from class com.bbn.openmap.io.BinaryFile
`MSBFirst`

Constructor Summary
`BinaryBufferedFile(java.io.File f)` Constructs a BinaryBufferedFile with a File
`BinaryBufferedFile(java.io.File f, int buffersize)` Constructs a BinaryBufferedFile with a File and a buffer size
`BinaryBufferedFile(java.lang.String name)` Constructs a BinaryBufferedFile with a filename
`BinaryBufferedFile(java.lang.String name, int buffersize)` Constructs a BinaryBufferedFile with a filename and a buffersize

Method Summary
`long` `available()` Return how many bytes left to be read in the file.
`static BinaryBufferedFile` `create(java.lang.String name)` A simple factory method that lets you try to create something without having to really deal with failure.
`static BinaryBufferedFile` `create(java.lang.String name, int buffersize)` A simple factory method that lets you try to create something without having to really deal with failure.
`void` `dispose()` Disposes the underlying file input, and releases some resources of the class.
`long` `getFilePointer()` Get the index of the next character to be read
`long` `length()` The length of the InputReader 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.
`char` `readChar()` Reads and returns a single byte, cast to a char.
`java.lang.String` `readFixedLengthString(int length)` Reads `length` bytes and returns a string composed of the bytes cast to chars.
`void` `readFloatArray(float[] vec, int offset, int len)` Reads an array of floats from the input.
`int` `readInteger()` Reads and returns a long.
`void` `readIntegerArray(int[] vec, int offset, int len)` Reads an array of integers.
`long` `readLong()` Reads and returns a long.
`short` `readShort()` Reads and returns a short.
`void` `readShortArray(short[] vec, int offset, int len)` Reads an array of shorts.
`int` `readUnsignedShort()` Reads and returns a integer from 2 bytes.
`void` `seek(long pos)` Set the index of the next character to be read.
`void` `setInputReader(InputReader reader)` Set the input reader used by the BinaryFile.
`long` `skipBytes(long n)` Skip over n bytes in the input file

Methods inherited from class com.bbn.openmap.io.BinaryFile
`addClosable, assertChar, byteOrder, byteOrder, close, closeClosable, exists, finalize, getInputReader, getName, readDouble, readFloat, readShortData, readToDelimiter, readUnsigned, removeClosable, setJarInputReader`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### BinaryBufferedFile

    public BinaryBufferedFile(java.io.File f,
                              int buffersize)
                       throws java.io.IOException

  Constructs a BinaryBufferedFile with a File and a buffer size

Parameters:
  `f` - the input file
  `buffersize` - the size to use for buffering reads
Throws:
  `java.io.IOException` - pass-through errors from opening a BinaryFile with f
See Also:
  `BinaryFile`

### BinaryBufferedFile

    public BinaryBufferedFile(java.io.File f)
                       throws java.io.IOException

  Constructs a BinaryBufferedFile with a File

Parameters:
  `f` - the input file
Throws:
  `java.io.IOException` - pass-through errors from opening a BinaryFile with f
See Also:
  `BinaryFile`

### BinaryBufferedFile

    public BinaryBufferedFile(java.lang.String name,
                              int buffersize)
                       throws java.io.IOException

  Constructs a BinaryBufferedFile with a filename and a buffersize

Parameters:
  `name` - the name/path of the input file
  `buffersize` - the size to use for buffering reads
Throws:
  `java.io.IOException` - pass-through errors from opening a BinaryFile with f
See Also:
  `BinaryFile`

### BinaryBufferedFile

    public BinaryBufferedFile(java.lang.String name)
                       throws java.io.IOException

  Constructs a BinaryBufferedFile with a filename

Parameters:
  `name` - the name/path of the input file
Throws:
  `java.io.IOException` - pass-through errors from opening a BinaryFile with f
See Also:
  `BinaryFile`

Method Detail

### create

    public static BinaryBufferedFile create(java.lang.String name)

  A simple factory method that lets you try to create something without having to really deal with failure. Returns a BinaryFile if successful, null if not.

### create

    public static BinaryBufferedFile create(java.lang.String name,
                                            int buffersize)

  A simple factory method that lets you try to create something without having to really deal with failure. Returns a BinaryFile if successful, null if not.

### setInputReader

    public void setInputReader(InputReader reader)

  Set the input reader used by the BinaryFile. Make sure it's intialized properly. Assumes that the pointer is at the beginning of the file.

  Overrides:
    `setInputReader` in class `BinaryFile`

### skipBytes

    public long skipBytes(long n)
                   throws java.io.IOException

  Description copied from class: `BinaryFile`
  Skip over n bytes in the input file

  Overrides:
    `skipBytes` in class `BinaryFile`
  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

    public long getFilePointer()
                        throws java.io.IOException

  Description copied from class: `BinaryFile`
  Get the index of the next character to be read

  Overrides:
    `getFilePointer` in class `BinaryFile`
  Returns:
    the index
  Throws:
    `java.io.IOException` - Any IO errors that occur in accessing the underlying file

### seek

    public void seek(long pos)
              throws java.io.IOException

  Description copied from class: `BinaryFile`
  Set the index of the next character to be read.

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

### length

    public long length()
                throws java.io.IOException

  Description copied from class: `BinaryFile`
  The length of the InputReader source.

  Overrides:
    `length` in class `BinaryFile`
  Throws:
    `java.io.IOException`

### available

    public long available()
                   throws java.io.IOException

  Description copied from class: `BinaryFile`
  Return how many bytes left to be read in the file.

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

### dispose

    public void dispose()
                 throws java.io.IOException

  Disposes the underlying file input, and releases some resources of the class. Calling any other members after this one will return bogus results.

  Overrides:
    `dispose` in class `BinaryFile`
  Throws:
    `java.io.IOException` - IO errors envountered in closing the file

### read

    public int read()
             throws java.io.IOException

  Description copied from class: `BinaryFile`
  Read from the file.

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

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws java.io.IOException

  Read from the file

  Overrides:
    `read` in class `BinaryFile`
  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

    public int read(byte[] b)
             throws java.io.IOException

  Description copied from class: `BinaryFile`
  Read from the file.

  Overrides:
    `read` in class `BinaryFile`
  Parameters:
    `b` - the byte array to read into. Equivelent 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

    public byte[] readBytes(int howmany,
                            boolean allowless)
                     throws java.io.EOFException,
                            FormatException

  Read from the file.

  Overrides:
    `readBytes` in class `BinaryFile`
  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.

### readChar

    public char readChar()
                  throws java.io.EOFException,
                         FormatException

  Reads and returns a single byte, cast to a char.

  Overrides:
    `readChar` in class `BinaryFile`
  Returns:
    the byte read from the file, cast to a char
  Throws:
    `java.io.EOFException` - the end-of-file has been reached, so no chars where available
    `FormatException` - a rethrown IOException

### readShort

    public short readShort()
                    throws java.io.EOFException,
                           FormatException

  Reads and returns a short.

  Overrides:
    `readShort` in class `BinaryFile`
  Returns:
    the 2 bytes merged into a short, according to the current byte ordering
  Throws:
    `java.io.EOFException` - there were less than 2 bytes left in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the short
  See Also:
    `read(byte[])`

### readUnsignedShort

    public int readUnsignedShort()
                          throws java.io.EOFException,
                                 FormatException

  Reads and returns a integer from 2 bytes.

  Overrides:
    `readUnsignedShort` in class `BinaryFile`
  Returns:
    the 2 bytes merged into a short, according to the current byte ordering, and then unsigned to int.
  Throws:
    `java.io.EOFException` - there were less than 2 bytes left in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the short
  See Also:
    `read(byte[])`

### readShortArray

    public void readShortArray(short[] vec,
                               int offset,
                               int len)
                        throws java.io.EOFException,
                               FormatException

  Reads an array of shorts.

  Parameters:
    `vec` - the array to write the shorts into
    `offset` - the first array index to write to
    `len` - the number of shorts to read
  Throws:
    `java.io.EOFException` - there were fewer bytes than needed in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the array

### readInteger

    public int readInteger()
                    throws java.io.EOFException,
                           FormatException

  Reads and returns a long.

  Overrides:
    `readInteger` in class `BinaryFile`
  Returns:
    the 4 bytes merged into a long, according to the current byte ordering
  Throws:
    `java.io.EOFException` - there were less than 4 bytes left in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the integer
  See Also:
    `BinaryFile.read(byte[])`

### readIntegerArray

    public void readIntegerArray(int[] vec,
                                 int offset,
                                 int len)
                          throws java.io.EOFException,
                                 FormatException

  Reads an array of integers.

  Overrides:
    `readIntegerArray` in class `BinaryFile`
  Throws:
    `java.io.EOFException` - there were fewer bytes than needed in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the array

### readFloatArray

    public void readFloatArray(float[] vec,
                               int offset,
                               int len)
                        throws java.io.EOFException,
                               FormatException

  Reads an array of floats from the input.

  Overrides:
    `readFloatArray` in class `BinaryFile`
  Parameters:
    `vec` - the vector to read into
    `offset` - the first float read goes into vec[offset]
    `len` - the number of floats to read from the stream
  Throws:
    `java.io.EOFException` - not enough bytes were left in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the integer

### readLong

    public long readLong()
                  throws java.io.EOFException,
                         FormatException

  Reads and returns a long.

  Overrides:
    `readLong` in class `BinaryFile`
  Returns:
    the 8 bytes merged into a long, according to the current byte ordering
  Throws:
    `java.io.EOFException` - there were less than 8 bytes left in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the long
  See Also:
    `read(byte[])`

### readFixedLengthString

    public java.lang.String readFixedLengthString(int length)
                                           throws java.io.EOFException,
                                                  FormatException

  Reads `length` bytes and returns a string composed of the bytes cast to chars.

  Overrides:
    `readFixedLengthString` in class `BinaryFile`
  Parameters:
    `length` - the number of bytes to read into the string
  Returns:
    the composed string
  Throws:
    `java.io.EOFException` - there were less than `length` bytes left in the file
    `FormatException` - rethrow of IOExceptions encountered while reading the bytes for the short

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