com.novell.java.io
Class EndianInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--com.novell.java.io.EndianInputStream

public class EndianInputStream
extends java.io.InputStream
implements EndianInput

Provides for writing primitive Java data types to a stream in an endian specific way.

Primitive data types are well understood types with associated operations. For example, an integer is considered to be a good primitive data type. The data can be converted back using an EndianInputStream.

See Also:
EndianInput

Constructor Summary
EndianInputStream(byte[] buffer)
          Creates a new EndianInputStream object that reads data from the specified byte array, which is not copied.
EndianInputStream(byte[] buffer, int offset, int length)
          Creates a new EndianInputStream object that reads data from the specified byte array.
 
Method Summary
 void align32()
          Aligns a value a on 32-bit boundary.
 int available()
          Returns the number of bytes that can be read from this input stream without blocking.
 void mark(int markpos)
          Sets the current marked position in the stream.
 boolean markSupported()
          Determines if EndianInputStream supports mark() and reset().
 int read()
          Reads the next byte of data from this input stream.
 int read(byte[] buffer, int offset, int length)
          Reads up to the specified bytes of data into an array of bytes from this input stream.
 boolean readBoolean()
          Reads a boolean value.
 byte readByte()
          Reads an 8-bit byte.
 char readChar()
          Reads a 16-bit char.
 double readDouble()
          Reads a 64-bit double.
 float readFloat()
          Reads a 32-bit float.
 void readFully(byte[] data)
          Reads bytes of data into a buffer, blocking until all bytes are read.
 void readFully(byte[] data, int offset, int length)
          Reads bytes of data into a buffer, blocking until all bytes are read.
 char readHiLoChar()
          Reads a 16-bit char from high-low order.
 java.lang.String readHiLoChars()
          Reads in a sequence of chars from high-low order that has been NULL-terminated or EOF.
 int readHiLoInt()
          Reads a 32-bit int from high-low order.
 long readHiLoLong()
          Reads a 64-bit long from high-low order.
 short readHiLoShort()
          Reads a 16-bit short from high-low order.
 java.lang.String readHiLoString()
          Reads in a sequence of chars from high-low order that has been length preceeded.
 int readInt()
          Reads a 32-bit integer.
 java.lang.String readLine()
          Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
 char readLoHiChar()
          Reads a 16-bit char from low-high order.
 java.lang.String readLoHiChars()
          Reads in a sequence of chars from low-high order that has been NULL-terminated or EOF.
 int readLoHiInt()
          Reads a 32-bit int from low-high order.
 long readLoHiLong()
          Reads a 64-bit long from low-high order.
 short readLoHiShort()
          Reads a 16-bit short from low-high order.
 long readLong()
          Reads a 64-bit long.
 short readShort()
          Reads an unsigned 8-bit byte.
 int readUnsignedByte()
          Reads an unsigned 8-bit byte.
 int readUnsignedShort()
          Reads an unsigned 16-bit short.
 java.lang.String readUString()
          Deprecated. Reads in a sequence of chars from low-high order that has been length preceeded and null-terminated.

 java.lang.String readUTF()
          Reads a UTF format String.
 void reset()
          Resets the buffer to the marked position.
 long skip(long n)
          Skips the specified bytes of input from this input stream.
 int skipBytes(int n)
          Skips the specified bytes, block until all bytes are skipped.
 void unpad(int n)
          Unpads a 32-bit value on the specified byte boundary.
 
Methods inherited from class java.io.InputStream
close, read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EndianInputStream

public EndianInputStream(byte[] buffer)
Creates a new EndianInputStream object that reads data from the specified byte array, which is not copied.
Parameters:
buffer - The input byte array buffer.

EndianInputStream

public EndianInputStream(byte[] buffer,
                         int offset,
                         int length)
Creates a new EndianInputStream object that reads data from the specified byte array. Up to length characters are read from the byte array, starting at the indicated offset. The byte array is not copied.
Parameters:
buf - The input buffer.
offset - The offset in the buffer for the first byte to read.
length - The maximum number of bytes to read from the buffer.
Method Detail

read

public int read()
Reads the next byte of data from this input stream. The byte value is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. The read() method of cannot block.
Returns:
The next byte of data, or -1 if the end of the stream has been reached.
Overrides:
read in class java.io.InputStream

read

public int read(byte[] buffer,
                int offset,
                int length)
Reads up to the specified bytes of data into an array of bytes from this input stream. This read() method cannot block.
Parameters:
buffer - The buffer into which the data is to be read.
offset - The start offset of the data.
length - The maximum number of bytes to read.
Returns:
The total number of bytes read into the buffer, or -1 if the end of the stream has been reached and there is no more data.
Overrides:
read in class java.io.InputStream

skip

public long skip(long n)
Skips the specified bytes of input from this input stream. Fewer bytes might be skipped if the end of the input stream is reached.
Parameters:
n - The number of bytes to be skipped.
Returns:
The actual number of bytes skipped.
Overrides:
skip in class java.io.InputStream

available

public int available()
Returns the number of bytes that can be read from this input stream without blocking. The available() method returns the value of count- position, which is the number of bytes remaining to be read from the input buffer.
Returns:
The number of bytes that can be read from the input stream without blocking.
Overrides:
available in class java.io.InputStream

markSupported

public boolean markSupported()
Determines if EndianInputStream supports mark() and reset().
Overrides:
markSupported in class java.io.InputStream

mark

public void mark(int markpos)
Sets the current marked position in the stream. EndianInputStream objects are marked by default at position zero when constructed. They may be marked at another position within the buffer by this method.
Overrides:
mark in class java.io.InputStream
See Also:
reset(), markSupported()

reset

public void reset()
Resets the buffer to the marked position. The marked position is the beginning unless another position was marked.
Overrides:
reset in class java.io.InputStream
See Also:
mark(int), markSupported()

readFully

public final void readFully(byte[] data)
                     throws java.io.IOException
Reads bytes of data into a buffer, blocking until all bytes are read.
Parameters:
data - The buffer into which the data is read
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readFully

public final void readFully(byte[] data,
                            int offset,
                            int length)
                     throws java.io.IOException
Reads bytes of data into a buffer, blocking until all bytes are read.
Parameters:
b - The buffer into which the data is read
off - The start offset of the data
len - The maximum number of bytes to read
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

skipBytes

public final int skipBytes(int n)
                    throws java.io.IOException
Skips the specified bytes, block until all bytes are skipped.
Parameters:
n - The number of bytes to be skipped
Returns:
The actual number of bytes skipped.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readBoolean

public final boolean readBoolean()
                          throws java.io.IOException
Reads a boolean value.
Returns:
The boolean value read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readByte

public final byte readByte()
                    throws java.io.IOException
Reads an 8-bit byte.
Returns:
The 8-bit byte read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readUnsignedByte

public final int readUnsignedByte()
                           throws java.io.IOException
Reads an unsigned 8-bit byte.
Returns:
The 8-bit byte read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readShort

public final short readShort()
                      throws java.io.IOException
Reads an unsigned 8-bit byte.
Returns:
The 8-bit byte read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readUnsignedShort

public final int readUnsignedShort()
                            throws java.io.IOException
Reads an unsigned 16-bit short.
Returns:
The 16-bit short read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readChar

public final char readChar()
                    throws java.io.IOException
Reads a 16-bit char.
Returns:
The 16-bit char read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readInt

public final int readInt()
                  throws java.io.IOException
Reads a 32-bit integer.
Returns:
The 32-bit integer read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readLong

public final long readLong()
                    throws java.io.IOException
Reads a 64-bit long.
Returns:
The read 64-bit long.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readFloat

public final float readFloat()
                      throws java.io.IOException
Reads a 32-bit float.
Returns:
The 32-bit float read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readDouble

public final double readDouble()
                        throws java.io.IOException
Reads a 64-bit double.
Returns:
The 64-bit double read.
Throws:
java.io.EOFException - If end of file is reached.
java.io.IOException - If any other I/O error has occurred.

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
Returns:
A String copy of the line.
Throws:
java.io.IOException - If an I/O error has occurred.

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Reads a UTF format String.
Returns:
The UTF format String.
Throws:
java.io.IOException - If an I/O error has occurred.

readHiLoChar

public final char readHiLoChar()
                        throws java.io.IOException
Reads a 16-bit char from high-low order.
Specified by:
readHiLoChar in interface EndianInput
Returns:
The read 16-bit char.
Throws:
java.io.IOException - If an I/O error has occurred.

readLoHiChar

public final char readLoHiChar()
                        throws java.io.IOException
Reads a 16-bit char from low-high order.
Specified by:
readLoHiChar in interface EndianInput
Returns:
The read 16-bit char.
Throws:
java.io.IOException - If an I/O error has occurred.

readHiLoChars

public final java.lang.String readHiLoChars()
                                     throws java.io.IOException
Reads in a sequence of chars from high-low order that has been NULL-terminated or EOF.
Returns:
A String copy of the sequence.
Throws:
java.io.IOException - If an I/O error has occurred.

readLoHiChars

public final java.lang.String readLoHiChars()
                                     throws java.io.IOException
Reads in a sequence of chars from low-high order that has been NULL-terminated or EOF.
Returns:
A String copy of the sequence.
Throws:
java.io.IOException - If an I/O error has occurred.

readHiLoString

public final java.lang.String readHiLoString()
                                      throws java.io.IOException
Reads in a sequence of chars from high-low order that has been length preceeded.
Returns:
A String copy of the sequence.
Throws:
java.io.IOException - If an I/O error has occurred.

readUString

public final java.lang.String readUString()
                                   throws java.io.IOException
Deprecated. Reads in a sequence of chars from low-high order that has been length preceeded and null-terminated.

Specified by:
readUString in interface EndianInput
Returns:
A String copy of the sequence.
Throws:
java.io.IOException - If an I/O error has occurred.

readHiLoInt

public final int readHiLoInt()
                      throws java.io.IOException
Reads a 32-bit int from high-low order.
Specified by:
readHiLoInt in interface EndianInput
Returns:
The 32-bit integer read.
Throws:
java.io.IOException - If an I/O error has occurred.

readLoHiInt

public final int readLoHiInt()
                      throws java.io.IOException
Reads a 32-bit int from low-high order.
Specified by:
readLoHiInt in interface EndianInput
Returns:
The 32-bit integer read.
Throws:
java.io.IOException - If an I/O error has occurred.

readHiLoShort

public final short readHiLoShort()
                          throws java.io.IOException
Reads a 16-bit short from high-low order.
Specified by:
readHiLoShort in interface EndianInput
Returns:
The 16-bit short read.
Throws:
java.io.IOException - If an I/O error has occurred.

readLoHiShort

public final short readLoHiShort()
                          throws java.io.IOException
Reads a 16-bit short from low-high order.
Specified by:
readLoHiShort in interface EndianInput
Returns:
The 16-bit short read.
Throws:
java.io.IOException - If an I/O error has occurred.

readHiLoLong

public final long readHiLoLong()
                        throws java.io.IOException
Reads a 64-bit long from high-low order.
Specified by:
readHiLoLong in interface EndianInput
Returns:
The 64-bit long read.
Throws:
java.io.IOException - If an I/O error has occurred.

readLoHiLong

public final long readLoHiLong()
                        throws java.io.IOException
Reads a 64-bit long from low-high order.
Specified by:
readLoHiLong in interface EndianInput
Returns:
The 64-bit long read.
Throws:
java.io.IOException - If an I/O error has occurred.

align32

public final void align32()
                   throws java.io.IOException
Aligns a value a on 32-bit boundary.
Throws:
java.io.IOException - If an I/O error has occurred.

unpad

public final void unpad(int n)
                 throws java.io.IOException
Unpads a 32-bit value on the specified byte boundary.
Parameters:
n - The byte boundry.
Throws:
java.io.IOException - If an I/O error has occurred.