FileInputReader (OpenMap API)
Date: 2016-12-09

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.bbn.openmap.io
Class FileInputReader

    java.lang.Object
      com.bbn.openmap.io.FileInputReader

All Implemented Interfaces:
  InputReader

    public class FileInputReader

extends java.lang.Object
implements InputReader

This class wraps a java.io.RandomAccessFile to allow us to choose the byte-order of the underlying file. It has a user-settable byte-ordering, which is then used to properly implement the various multibyte reading members. Used for reading local files.

See Also:
  `RandomAccessFile`, `InputReader`, `BinaryFile`

Field Summary
`protected java.lang.String` | `absolutePath` Needed for reopening files that have been closed.
`protected java.io.RandomAccessFile` | `inputFile` The underlying file input
`protected java.lang.String` | `name` Needed for input reader interface.

Constructor Summary
`FileInputReader(java.io.File f)` Constructs a new BinaryFile with the specified file as the input.
`FileInputReader(java.lang.String f)` Constructs a new BinaryFile with the specified file as the input.

Method Summary
`long` | `available()` Return how many bytes left to be read in the file.
`java.io.RandomAccessFile` | `checkInputFile()`
`void` | `close()` Closes the underlying file
`java.lang.String` | `getAbsolutePath()`
`long` | `getFilePointer()` Get the index of the next character to be read
`java.io.RandomAccessFile` | `getInputFile()` Get the RandomAccessFile, for querying purposes only.
`java.lang.String` | `getName()` Get the file name.
`protected java.io.RandomAccessFile` | `init(java.io.File f)` Initialize the underlying RandomAccessFile.
`long` | `length()` Local files only.
`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

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

Field Detail

### inputFile

    protected java.io.RandomAccessFile inputFile

  The underlying file input

### name

    protected java.lang.String name

  Needed for input reader interface.

### absolutePath

    protected java.lang.String absolutePath

  Needed for reopening files that have been closed.

Constructor Detail

### FileInputReader

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

  Constructs a new BinaryFile with the specified file as the input. The default byte-order is LSB first. Reads start at the first byte of the file.

  Parameters:
    `f` - the file to be opened for reading
  Throws:
    `java.io.IOException` - pass-through errors from opening a RandomAccessFile with f
  See Also:
    `RandomAccessFile`

### FileInputReader

    public FileInputReader(java.lang.String f)
                    throws java.io.IOException

  Constructs a new BinaryFile with the specified file as the input. The default byte-order is LSB first. Reads start at the first byte of the file.

  Parameters:
    `f` - the path to the file to be opened for reading.
  Throws:
    `java.io.IOException` - pass-through errors from opening a RandomAccessFile with f
  See Also:
    `RandomAccessFile`

Method Detail

### getName

    public java.lang.String getName()

  Get the file name.

  Specified by:
    `getName` in interface `InputReader`

### getAbsolutePath

    public java.lang.String getAbsolutePath()

  Returns:
    the absolute path of the file.

### init

    protected java.io.RandomAccessFile init(java.io.File f)
                                     throws java.io.IOException

  Initialize the underlying RandomAccessFile. If it's found, but there are too many files open, it calls BinaryFile.closeClosable to try to get an open file pointer from the system, and then tries again.

  Parameters:
    `f` - a java.io.File
  Throws:
    `java.io.IOException`

### getInputFile

    public java.io.RandomAccessFile getInputFile()

  Get the RandomAccessFile, for querying purposes only. Don't use it to get data!

### checkInputFile

    public java.io.RandomAccessFile checkInputFile()
                                            throws java.io.IOException

  Throws:
    `java.io.IOException`

### skipBytes

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

  Skip over n bytes in the input file

  Specified by:
    `skipBytes` in interface `InputReader`
  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

  Get the index of the next character to be read

  Specified by:
    `getFilePointer` in interface `InputReader`
  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

  Set the index of the next character to be read.

  Specified by:
    `seek` in interface `InputReader`
  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

  Local files only. Retrieve the length of the file being accessed.

  Specified by:
    `length` in interface `InputReader`
  Returns:
    the length of the file (counted in bytes)
  Throws:
    `java.io.IOException` - Any IO errors that occur in accessing the underlying file.

### available

    public long available()
                   throws java.io.IOException

  Return how many bytes left to be read in the file.

  Specified by:
    `available` in interface `InputReader`
  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

    public void close()
               throws java.io.IOException

  Closes the underlying file

  Specified by:
    `close` in interface `InputReader`
  Throws:
    `java.io.IOException` - Any IO errors encountered in accessing the file

### read

    public int read()
             throws java.io.IOException

  Read from the file.

  Specified by:
    `read` in interface `InputReader`
  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

  Specified by:
    `read` in interface `InputReader`
  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

  Read from the file.

  Specified by:
    `read` in interface `InputReader`
  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

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

  Read from the file.

  Specified by:
    `readBytes` in interface `InputReader`
  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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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