StreamInputReader (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 StreamInputReader

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

All Implemented Interfaces:
  InputReader

Direct Known Subclasses:
  ByteArrayInputReader, JarInputReader, URLInputReader

    public abstract class StreamInputReader

extends java.lang.Object
implements InputReader

An Abstract InputReader to handle reading data from streams, where seeking to a place in the file in front of the current pointer involves closing the stream, and re-seeking from the beginning.

See Also:
  `InputReader`, `BinaryFile`

Field Summary
`protected java.io.InputStream` | `inputStream` The underlying data input stream, for resource files.
`protected long` | `inputStreamCount` Keep track of how many bytes have been read when using the DataInputStream to read the file.
`protected java.lang.String` | `name` The source name.

Constructor Summary
`StreamInputReader()`

Method Summary
`long` | `available()` Return how many bytes the input stream thinks are available.
`void` | `close()` Closes the underlying file
`protected int` | `count(int add)` Add the number of bytes to the inputStreamCount.
`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 how many bytes the input stream thinks make up the file.
`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.
`protected void` | `reopen()` Reset the DataInputStream to the beginning, by closing the current connection and reopening it.
`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

### inputStream

    protected java.io.InputStream inputStream

  The underlying data input stream, for resource files. Is used if the inputFile is null.

### inputStreamCount

    protected long inputStreamCount

  Keep track of how many bytes have been read when using the DataInputStream to read the file.

### name

    protected java.lang.String name

  The source name.

Constructor Detail

### StreamInputReader

    public StreamInputReader()

Method Detail

### getName

    public java.lang.String getName()

  Description copied from interface: `InputReader`
  Get the name of the source.

  Specified by:
    `getName` in interface `InputReader`

### count

    protected int count(int add)

  Add the number of bytes to the inputStreamCount.

  Returns:
    number of bytes added in this call, to pass along to anything else that will be interested.

### reopen

    protected void reopen()
                   throws java.io.IOException

  Reset the DataInputStream to the beginning, by closing the current connection and reopening it. The StreamInputReader method simply closes the input stream and resets the input stream count, so the implementation of this class needs to reopen the stream at the beginning of the source file.

  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

  Return how many bytes the input stream thinks make up the file. This is calculated by adding the number of bytes read to the number of bytes available. May not be reliable.

  Specified by:
    `length` 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

### available

    public long available()
                   throws java.io.IOException

  Return how many bytes the input stream thinks are available.

  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