com.sshtools.util
Class ByteArrayReader

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.ByteArrayInputStream
              |
              +--com.sshtools.util.ByteArrayReader

public class ByteArrayReader
extends java.io.ByteArrayInputStream

Provides a reader type interface into the ByteArrayInputStream.

Version:
1.0
Author:
Lee David Painter ( lee@sshtools.com )

Field Summary
 
Fields inherited from class java.io.ByteArrayInputStream
buf, count, mark, pos
 
Constructor Summary
ByteArrayReader(byte[] data)
          Constructor for the ByteArrayReader object
 
Method Summary
static int previewInt(byte[] data, int start)
          Previews an integer in the byte array provided.
 java.math.BigInteger readBigInteger()
          Returns a BigInteger from the byte array.
 byte[] readBinaryString()
          Returns a binary string from the byte array.
 long readInt()
           Reads an integer from the byte array.
 java.lang.String readString()
          Reads a string from the byte array, the format of the string will be 4 bytes representing an int value for the lengh of the string and then len bytes of data.
 
Methods inherited from class java.io.ByteArrayInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.io.InputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayReader

public ByteArrayReader(byte[] data)
Constructor for the ByteArrayReader object

Parameters:
data - The byte array to be read.
Method Detail

readInt

public long readInt()
             throws java.io.IOException

Reads an integer from the byte array.

NOTE: This currently returns a long but only extracts 4 bytes. The reason behind this is that this class has been designed for SSH byte arrays; SSH uses unsigned integers but in java we do not have an unsigned integer type. To safely return the non negative value we must extract the byte information into a long to preserve the unsigned value. THIS WILL BE UPDATED SOON WITH THE UnsignedInteger class.

Returns:
Description of the Return Value
Throws:
java.io.IOException - Description of the Exception

previewInt

public static int previewInt(byte[] data,
                             int start)
Previews an integer in the byte array provided. The method reads 4 bytes from the position in the array specified by start and returns the integer value

Parameters:
data - The byte array to preview
start - The start position in the array
Returns:
The int value

readString

public java.lang.String readString()
                            throws java.io.IOException
Reads a string from the byte array, the format of the string will be 4 bytes representing an int value for the lengh of the string and then len bytes of data.

Returns:
A the string read from the byte array
Throws:
java.io.IOException - Thrown of the data cannot be read

readBinaryString

public byte[] readBinaryString()
                        throws java.io.IOException
Returns a binary string from the byte array. The method first reads an integer to obtain the length of the data and then reads the data which is returned in the byte array

Returns:
The binary data read
Throws:
java.io.IOException - Thrown if the data cannot be read

readBigInteger

public java.math.BigInteger readBigInteger()
                                    throws java.io.IOException
Returns a BigInteger from the byte array. The methos first reads the length of the BigInteger data and then reads and creates a BigInteger from the data read.

Returns:
The BigInteger value read
Throws:
java.io.IOException - Thrown if the data cannot be read


Copyright © 2002 Sshtools.com. All Rights Reserved.