org.walluck.io
Class DataInputStreamEx

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byjava.io.DataInputStream
              extended byorg.walluck.io.DataInputStreamEx
All Implemented Interfaces:
java.io.DataInput
Direct Known Subclasses:
LittleEndianInputStream

public class DataInputStreamEx
extends java.io.DataInputStream

A DataInputStream with a few more methods.

Since:
1.0
Version:
1.0
Author:
David Walluck
See Also:
DataInputStream

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
DataInputStreamEx(java.io.InputStream is)
          Creates a new data input stream ex.
 
Method Summary
 byte[] readBytes(int length)
          Read exactly the specified number of bytes from the stream.
 java.lang.String readString(int length)
          Read a string of the specified length from the stream.
 java.lang.String readString0(short length)
          Read a null-terminated string of the specified length from the stream.
 java.lang.String readStringL()
          Read a byte length prefixed string from the stream.
 java.lang.String readStringLL()
          Read a short length prefixed string from the stream.
 java.lang.String readStringNullPadded(int length, java.lang.String charset)
          Read a null-padded string of length from an input stream.
 java.lang.String readStringUntilNull(int length)
          Read a string from an input stream until a null is reached.
 
Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytes
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataInputStreamEx

public DataInputStreamEx(java.io.InputStream is)
Creates a new data input stream ex.

Parameters:
is - the underlying input stream
Method Detail

readString

public java.lang.String readString(int length)
                            throws java.io.IOException
Read a string of the specified length from the stream.

Parameters:
length - the length
Returns:
the string
Throws:
java.io.IOException - if an error occurs

readString0

public java.lang.String readString0(short length)
                             throws java.io.IOException
Read a null-terminated string of the specified length from the stream.

Parameters:
length - the length
Returns:
the string
Throws:
java.io.IOException - if an error occurs

readStringL

public java.lang.String readStringL()
                             throws java.io.IOException
Read a byte length prefixed string from the stream.

Returns:
the string
Throws:
java.io.IOException - if an error occurs

readStringLL

public java.lang.String readStringLL()
                              throws java.io.IOException
Read a short length prefixed string from the stream.

Returns:
the string
Throws:
java.io.IOException - if an error occurs

readBytes

public byte[] readBytes(int length)
                 throws java.io.IOException
Read exactly the specified number of bytes from the stream.

Parameters:
length - the length
Returns:
the byte array
Throws:
java.io.IOException - if an error occurs

readStringUntilNull

public java.lang.String readStringUntilNull(int length)
                                     throws java.io.IOException
Read a string from an input stream until a null is reached.

Parameters:
length - the maximum length that the string can be
Returns:
the string
Throws:
java.io.IOException - if an error occurs

readStringNullPadded

public java.lang.String readStringNullPadded(int length,
                                             java.lang.String charset)
                                      throws java.io.IOException
Read a null-padded string of length from an input stream.

Parameters:
length - the maximum length that the tring can be
charset - the Java charset
Returns:
the string
Throws:
java.io.IOException - if an error occurs