Secure iNet Factory

com.jscape.inet.ssh
Class SshReader

java.lang.Object
  extended by com.jscape.inet.ssh.SshReader

public class SshReader
extends java.lang.Object

Reads the basic SSH types from the underalyed input stream.

Version:
1.0
Author:
Alex Usun

Constructor Summary
SshReader(byte[] data)
          Creates a new reader instance for the specified byte array.
SshReader(java.io.InputStream in, boolean owner)
          Creates a new reader instance.
 
Method Summary
 void close()
          Closes the current reader.
 boolean readBoolean()
          Reads a SSH boolean value.
 int readByte()
          Reads a SSH byte value.
 void readFully(byte[] b)
          Reads the data into specified buffer.
 void readFully(byte[] b, int offset, int length)
          Reads the data into specified buffer.
 int readInt32()
          Reads a SSH int32 value.
 long readInt64()
          Reads a SSH int64 value.
 java.lang.String readLine()
          Reads a string separated by "\r\n" symbols.
 java.math.BigInteger readMpint()
          Reads a SSH mpint value.
 java.lang.String[] readNameList()
          Reads a SSH name list.
 java.lang.String readString()
          Reads a SSH string.
 byte[] readStringAsByteArray()
          Reads a SSH string and returns it as a byte array.
 long readUint32()
          Reads a SSH uint32 value.
 java.math.BigInteger readUint64()
          Reads a SSH uint64 value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SshReader

public SshReader(byte[] data)
Creates a new reader instance for the specified byte array.

Parameters:
data - the data source

SshReader

public SshReader(java.io.InputStream in,
                 boolean owner)
Creates a new reader instance.

Parameters:
in - the underlayed input stream
owner - if true the reader will close the underlayed stream while its own closing
Method Detail

close

public void close()
Closes the current reader.


readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Reads a SSH boolean value. A SSH boolean value is stored as a single byte. The value 0 represents FALSE, and the value 1 represents TRUE. All non-zero values are interpreted as TRUE.

Returns:
a readed boolean value
Throws:
java.io.IOException - if an I/O error occurs

readByte

public int readByte()
             throws java.io.IOException
Reads a SSH byte value. A SSH byte represents an arbitrary 8-bit value (octet) in range [0..255]. Since Java doesn't provide an unsigned types the readed value is returned as int.

Returns:
a readed byte value
Throws:
java.io.IOException - if an I/O error occurs

readUint32

public long readUint32()
                throws java.io.IOException
Reads a SSH uint32 value. A SSH uint32 represents a 32-bit unsigned integer stored as four bytes in the order of decreasing significance (network byte order). Since Java doesn't provide an unsigned types the readed value is returned as long.

Returns:
a readed uint32 value
Throws:
java.io.IOException - if an I/O error occurs

readInt32

public int readInt32()
              throws java.io.IOException
Reads a SSH int32 value. A SSH uint32 represents a 32-bit signed integer stored as four bytes in the order of decreasing significance (network byte order).

Returns:
a readed int32 value
Throws:
java.io.IOException - if an I/O error occurs

readUint64

public java.math.BigInteger readUint64()
                                throws java.io.IOException
Reads a SSH uint64 value. A SSH uint64 value represents a 64-bit unsigned integer. Stored as eight bytes in the order of decreasing significance (network byte order).

Returns:
a readed uint64 value
Throws:
java.io.IOException - if an I/O error occurs

readInt64

public long readInt64()
               throws java.io.IOException
Reads a SSH int64 value. A SSH uint64 value represents a 64-bit signed integer. Stored as eight bytes in the order of decreasing significance (network byte order).

Returns:
a readed int64 value
Throws:
java.io.IOException - if an I/O error occurs

readString

public java.lang.String readString()
                            throws java.io.IOException
Reads a SSH string. A SSH string is allowed to contain arbitrary binary data, including null characters and 8-bit characters. It is stored as a uint32 containing its length (number of bytes that follow) and zero (= empty string) or more bytes that are the value of the string. Terminating null characters are not used.

Returns:
a readed string
Throws:
java.io.IOException - if an I/O error occurs

readStringAsByteArray

public byte[] readStringAsByteArray()
                             throws java.io.IOException
Reads a SSH string and returns it as a byte array.

Returns:
a readed string
Throws:
java.io.IOException - if an I/O error occurs

readMpint

public java.math.BigInteger readMpint()
                               throws java.io.IOException
Reads a SSH mpint value. A SSH mpint represents multiple precision integers in two's complement format, stored as a string, 8 bits per byte, MSB first. Negative numbers have the value 1 as the most significant bit of the first byte of the data partition. If the most significant bit would be set for a positive number, the number is preceded by a zero byte.

Returns:
a readed mpint value
Throws:
java.io.IOException - if an I/O error occurs

readNameList

public java.lang.String[] readNameList()
                                throws java.io.IOException
Reads a SSH name list. A SSH anme list is a string containing a comma separated list of names. A name list is represented as a uint32 containing its length (number of bytes that follow) followed by a comma-separated list of zero or more names. A name must be non-zero length, and it must not contain a comma (','). Context may impose additional restrictions on the names; for example, the names in a list may have to be valid algorithm identifier (see Section 6 below), or [RFC3066] language tags. The order of the names in a list may or may not be significant, also depending on the context where the list is is used. Terminating NUL characters are not used, neither for the individual names, nor for the list as a whole.

Returns:
a readed name list
Throws:
java.io.IOException - if an I/O error occurs

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads a string separated by "\r\n" symbols.

Returns:
a readed string without ending "\r\n"
Throws:
java.io.IOException - if an I/O error occurs

readFully

public void readFully(byte[] b)
               throws java.io.IOException
Reads the data into specified buffer.

Parameters:
b - the data buffer.
Throws:
java.io.IOException - if an I/O error occurs

readFully

public void readFully(byte[] b,
                      int offset,
                      int length)
               throws java.io.IOException
Reads the data into specified buffer.

Parameters:
b - the data buffer
offset - the buffer offset
length - the data length
Throws:
java.io.IOException - if an I/O error occurs

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved