jautil
Class JAInputStream

java.lang.Object
  extended by jautil.JAInputStream

public class JAInputStream
extends java.lang.Object

A Java ARP input-stream wraps a standard input-stream, and provides little-endian binary input methods for values of several primitive types.


Constructor Summary
JAInputStream(java.io.InputStream instrm)
          Constructs the input-stream, based on the given input-stream, which is assumed to be unbuffered.
 
Method Summary
 void close()
          Closes this stream.
 int read()
          Does a plain single-byte read on the underlying stream.
 boolean readBoolean()
          Reads a boolean value, represented as a byte value in {0,1}.
 void readBuf(byte[] bb, int pos, int n)
          Reads a byte-sequence from this stream, in to the given buffer, at the given positon, and of the given length.
 java.nio.ByteBuffer readByteBuffer(int N)
          Creates and returns a (direct) byte buffer of the given size from this stream, throwing an IO-exception if the actual size does not match that specified.
 byte[] readBytes(boolean compressed)
          Reads and returns an array of bytes from this stream, performing GZIP inflation if necessary.
 float readFloat()
          Reads a (4-byte) float from this stream.
 java.awt.image.BufferedImage readImage()
          Reads a buffered-image directly from this stream.
 java.awt.image.BufferedImage readImage(boolean compressed)
          Reads a possibly-compressed data block from this stream, converts it to a buffered-image, and returns this image.
 int readInt()
          Reads a (4-byte, little-endian) integer from this stream.
 java.lang.String readString()
          Reads a length-prefixed string of ASCII (really, ISO-8859) characters from this stream.
 short readUnsignedShort()
          Reads a (2-byte) unsigned short integer from this stream, returning it as a short (so a large unsigned-short will be returned as a negative short, in accordance with the usual 2's complement conventions).
 void switchToUnGZIP()
          Wrap this Java ARP stream's underlying input stream with a GZIPInputStream, so that GZIP inflation is performed on all subsequent input.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JAInputStream

public JAInputStream(java.io.InputStream instrm)
              throws java.io.IOException
Constructs the input-stream, based on the given input-stream, which is assumed to be unbuffered.

Throws:
java.io.IOException
Method Detail

close

public void close()
           throws java.io.IOException
Closes this stream.

Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Does a plain single-byte read on the underlying stream.

Throws:
java.io.IOException

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Reads a boolean value, represented as a byte value in {0,1}.

Throws:
java.io.IOException

readInt

public int readInt()
            throws java.io.IOException
Reads a (4-byte, little-endian) integer from this stream.

Throws:
java.io.IOException

readUnsignedShort

public short readUnsignedShort()
                        throws java.io.IOException
Reads a (2-byte) unsigned short integer from this stream, returning it as a short (so a large unsigned-short will be returned as a negative short, in accordance with the usual 2's complement conventions).

Throws:
java.io.IOException

readFloat

public float readFloat()
                throws java.io.IOException
Reads a (4-byte) float from this stream.

Throws:
java.io.IOException

readString

public java.lang.String readString()
                            throws java.io.IOException
Reads a length-prefixed string of ASCII (really, ISO-8859) characters from this stream.

Throws:
java.io.IOException

readImage

public java.awt.image.BufferedImage readImage()
                                       throws java.io.IOException
Reads a buffered-image directly from this stream.

Throws:
java.io.IOException

readImage

public java.awt.image.BufferedImage readImage(boolean compressed)
                                       throws java.io.IOException
Reads a possibly-compressed data block from this stream, converts it to a buffered-image, and returns this image.

Throws:
java.io.IOException

readBuf

public void readBuf(byte[] bb,
                    int pos,
                    int n)
             throws java.io.IOException
Reads a byte-sequence from this stream, in to the given buffer, at the given positon, and of the given length.

Throws:
java.io.IOException

readBytes

public byte[] readBytes(boolean compressed)
                 throws java.io.IOException
Reads and returns an array of bytes from this stream, performing GZIP inflation if necessary. The stream is assumed to contain at its current position an integer byte-count followed by a data block of that size. If the compressed flag is set, this block is assumed to require GZIP inflation in order to obtain the actual result; in this case the inflated data is itself assumed to consist of an integer byte-count followed by a data block of that size, this block being the final result.

Throws:
java.io.IOException

readByteBuffer

public java.nio.ByteBuffer readByteBuffer(int N)
                                   throws java.io.IOException
Creates and returns a (direct) byte buffer of the given size from this stream, throwing an IO-exception if the actual size does not match that specified.

Throws:
java.io.IOException

switchToUnGZIP

public void switchToUnGZIP()
                    throws java.io.IOException
Wrap this Java ARP stream's underlying input stream with a GZIPInputStream, so that GZIP inflation is performed on all subsequent input.

Throws:
java.io.IOException