org.jagatoo.util.streams
Class StreamUtils

java.lang.Object
  extended by org.jagatoo.util.streams.StreamUtils

public class StreamUtils
extends java.lang.Object

Contains static utility methods for Stream.


Constructor Summary
StreamUtils()
           
 
Method Summary
static byte[] buildByteArray(java.io.InputStream in)
          This calls buildByteArray(InputStream, int) with an initialSize of in.available().
static byte[] buildByteArray(java.io.InputStream in, int initialSize)
          Builds a byte-array from the given InputStream.
static byte readByte(java.io.BufferedInputStream in)
          Reads one byte from the InputStream.
static byte readByte(java.io.InputStream in)
          Reads one byte from the InputStream.
static void readBytes(java.io.BufferedInputStream in, int bytesToRead, byte[] buffer, int bufferOffset)
          Reads bytesToRead bytes from the stream.
static void readBytes(java.io.InputStream in, int bytesToRead, byte[] buffer, int bufferOffset)
          Reads bytesToRead bytes from the stream.
static java.lang.String readCString(java.io.InputStream in, int maxLength, boolean alwaysReadMaxLength)
          Reads a String from the InputStream.
static int readInt(java.io.BufferedInputStream in)
          Reads one (signed) int from the stream.
static int readInt(java.io.InputStream in)
          Reads one (signed) int from the stream.
static short readShort(java.io.BufferedInputStream in)
          Reads two bytes from the InputStream stored in a short-value.
static short readShort(java.io.InputStream in)
          Reads two bytes from the InputStream stored in a short-value.
static int readSwappedInt(java.io.BufferedInputStream in)
          Reads one (signed) int from the stream.
static int readSwappedInt(java.io.InputStream in)
          Reads one (signed) int from the stream.
static short readSwappedShort(java.io.BufferedInputStream in)
          Reads two bytes from the InputStream stored in a short-value.
static short readSwappedShort(java.io.InputStream in)
          Reads two bytes from the InputStream stored in a short-value.
static int readSwappedUnsignedShort(java.io.BufferedInputStream in)
          Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.
static int readSwappedUnsignedShort(java.io.InputStream in)
          Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.
static short readUnsignedByte(java.io.BufferedInputStream in)
          Reads one unsigned byte from the InputStream stored in a short-value to preserve the sign.
static short readUnsignedByte(java.io.InputStream in)
          Reads one unsigned byte from the InputStream stored in a short-value to preserve the sign.
static int readUnsignedShort(java.io.BufferedInputStream in)
          Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.
static int readUnsignedShort(java.io.InputStream in)
          Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.
static void skipBytes(java.io.BufferedInputStream in, long toSkip)
          Skips and discards the given number of bytes from the given stream.
static void skipBytes(java.io.InputStream in, long toSkip)
          Skips and discards the given number of bytes from the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamUtils

public StreamUtils()
Method Detail

skipBytes

public static final void skipBytes(java.io.InputStream in,
                                   long toSkip)
                            throws java.io.IOException
Skips and discards the given number of bytes from the given stream.

Parameters:
in -
toSkip -
Throws:
java.io.IOException

skipBytes

public static final void skipBytes(java.io.BufferedInputStream in,
                                   long toSkip)
                            throws java.io.IOException
Skips and discards the given number of bytes from the given stream.

Parameters:
in -
toSkip -
Throws:
java.io.IOException

readByte

public static final byte readByte(java.io.InputStream in)
                           throws java.io.IOException
Reads one byte from the InputStream.

Parameters:
in -
Returns:
the read byte.
Throws:
java.io.IOException

readByte

public static final byte readByte(java.io.BufferedInputStream in)
                           throws java.io.IOException
Reads one byte from the InputStream.

Parameters:
in -
Returns:
the read byte.
Throws:
java.io.IOException

readUnsignedByte

public static final short readUnsignedByte(java.io.InputStream in)
                                    throws java.io.IOException
Reads one unsigned byte from the InputStream stored in a short-value to preserve the sign.

Parameters:
in -
Returns:
the read unsigned byte as a short.
Throws:
java.io.IOException

readUnsignedByte

public static final short readUnsignedByte(java.io.BufferedInputStream in)
                                    throws java.io.IOException
Reads one unsigned byte from the InputStream stored in a short-value to preserve the sign.

Parameters:
in -
Returns:
the read unsigned byte as a short.
Throws:
java.io.IOException

readShort

public static final short readShort(java.io.InputStream in)
                             throws java.io.IOException
Reads two bytes from the InputStream stored in a short-value.

Parameters:
in -
Returns:
the read short.
Throws:
java.io.IOException

readShort

public static final short readShort(java.io.BufferedInputStream in)
                             throws java.io.IOException
Reads two bytes from the InputStream stored in a short-value.

Parameters:
in -
Returns:
the read short.
Throws:
java.io.IOException

readUnsignedShort

public static final int readUnsignedShort(java.io.InputStream in)
                                   throws java.io.IOException
Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.

Parameters:
in -
Returns:
the read unsigned short (as an int).
Throws:
java.io.IOException

readUnsignedShort

public static final int readUnsignedShort(java.io.BufferedInputStream in)
                                   throws java.io.IOException
Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.

Parameters:
in -
Returns:
the read unsigned short (as an int).
Throws:
java.io.IOException

readSwappedShort

public static final short readSwappedShort(java.io.InputStream in)
                                    throws java.io.IOException
Reads two bytes from the InputStream stored in a short-value.

Parameters:
in -
Returns:
the read short.
Throws:
java.io.IOException

readSwappedShort

public static final short readSwappedShort(java.io.BufferedInputStream in)
                                    throws java.io.IOException
Reads two bytes from the InputStream stored in a short-value.

Parameters:
in -
Returns:
the read short.
Throws:
java.io.IOException

readSwappedUnsignedShort

public static final int readSwappedUnsignedShort(java.io.InputStream in)
                                          throws java.io.IOException
Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.

Parameters:
in -
Returns:
the read unsigned short (as an int).
Throws:
java.io.IOException

readSwappedUnsignedShort

public static final int readSwappedUnsignedShort(java.io.BufferedInputStream in)
                                          throws java.io.IOException
Reads two bytes from the InputStream, convertes them to a short and stores them to an int to preserve the sign.

Parameters:
in -
Returns:
the read unsigned short (as an int).
Throws:
java.io.IOException

readInt

public static final int readInt(java.io.InputStream in)
                         throws java.io.IOException
Reads one (signed) int from the stream.

Parameters:
in -
Returns:
the read int.
Throws:
java.io.IOException

readInt

public static final int readInt(java.io.BufferedInputStream in)
                         throws java.io.IOException
Reads one (signed) int from the stream.

Parameters:
in -
Returns:
the read int.
Throws:
java.io.IOException

readSwappedInt

public static final int readSwappedInt(java.io.InputStream in)
                                throws java.io.IOException
Reads one (signed) int from the stream.

Parameters:
in -
Returns:
the read int.
Throws:
java.io.IOException

readSwappedInt

public static final int readSwappedInt(java.io.BufferedInputStream in)
                                throws java.io.IOException
Reads one (signed) int from the stream.

Parameters:
in -
Returns:
the read int.
Throws:
java.io.IOException

readBytes

public static final void readBytes(java.io.InputStream in,
                                   int bytesToRead,
                                   byte[] buffer,
                                   int bufferOffset)
                            throws java.io.IOException
Reads bytesToRead bytes from the stream.

Parameters:
in -
bytesToRead -
buffer -
bufferOffset -
Throws:
java.io.IOException

readBytes

public static final void readBytes(java.io.BufferedInputStream in,
                                   int bytesToRead,
                                   byte[] buffer,
                                   int bufferOffset)
                            throws java.io.IOException
Reads bytesToRead bytes from the stream.

Parameters:
in -
bytesToRead -
buffer -
bufferOffset -
Throws:
java.io.IOException

readCString

public static final java.lang.String readCString(java.io.InputStream in,
                                                 int maxLength,
                                                 boolean alwaysReadMaxLength)
                                          throws java.io.IOException
Reads a String from the InputStream. The string is expected to be 0-terminated.

Parameters:
in -
maxLength -
alwaysReadMaxLength -
Returns:
the read String.
Throws:
java.io.IOException

buildByteArray

public static final byte[] buildByteArray(java.io.InputStream in,
                                          int initialSize)
                                   throws java.io.IOException
Builds a byte-array from the given InputStream.
The byte-array is created with a size of initialSize and is enlarged on demand.
The InputStream is NOT closed at the end.

Parameters:
in - the InputStream to get data from
initialSize - the initial size of the output byte-array
Returns:
the filled and correctly sized byte-array
Throws:
java.io.IOException

buildByteArray

public static final byte[] buildByteArray(java.io.InputStream in)
                                   throws java.io.IOException
This calls buildByteArray(InputStream, int) with an initialSize of in.available().

Parameters:
in - the InputStream to get data from
Returns:
the filled and correctly sized byte-array
Throws:
java.io.IOException