net.sf.btw.commons
Class StreamUtils

java.lang.Object
  extended by net.sf.btw.commons.StreamUtils

public final class StreamUtils
extends Object

Utilities for working with streams.

Author:
Martin Vysny

Method Summary
static byte[] readByteArray(InputStream in)
          Reads the byte array from the input stream.
static int readPackedInt(InputStream in)
          Reads the number in a packed format.
static byte[] stringToByteArray(String string)
          Writes given string to data output stream as a string.
static void writeByteArray(byte[] bytes, OutputStream out)
          Writes the byte array to the output stream.
static void writePackedInt(int number, OutputStream out)
          Writes the number in a packed format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeByteArray

public static void writeByteArray(byte[] bytes,
                                  OutputStream out)
                           throws IOException
Writes the byte array to the output stream.

Parameters:
bytes - the bytes to write. Handles null array correctly.
out - writes to this stream.
Throws:
IOException - if write fails.

readByteArray

public static byte[] readByteArray(InputStream in)
                            throws IOException
Reads the byte array from the input stream. The array must have been written by writeByteArray(byte[], OutputStream).

Parameters:
in - reads from this stream.
Returns:
byte array, may be null if a null array was written.
Throws:
IOException - if read fails.

writePackedInt

public static void writePackedInt(int number,
                                  OutputStream out)
                           throws IOException
Writes the number in a packed format. The number may occupy 1-5 bytes depending on its value.

Parameters:
number - the number to write
out - the output stream.
Throws:
IOException

readPackedInt

public static int readPackedInt(InputStream in)
                         throws IOException
Reads the number in a packed format. The number may occupy 1-5 bytes depending on its value.

Parameters:
in - the input stream.
Returns:
the number.
Throws:
IOException

stringToByteArray

public static byte[] stringToByteArray(String string)
Writes given string to data output stream as a string. This method is incompatible with String.getBytes(); use DataInputStream.readUTF() instead.

Parameters:
string - string to convert. Cannot be null.
Returns:
array of bytes.


Copyright © 2007 Moto a Judas. All Rights Reserved.