org.extex.util.file.random
Class RandomAccessInputStream

java.lang.Object
  extended by org.extex.util.file.random.RandomAccessInputStream
All Implemented Interfaces:
java.io.DataInput, RandomAccessR

public class RandomAccessInputStream
extends java.lang.Object
implements RandomAccessR

RandomAccess for a InputStream

Version:
$Revision: 5921 $
Author:
Michael Niedermair

Field Summary
static int SHIFT16
          Shift 16
static int SHIFT24
          Shift 24
static int SHIFT32
          Shift 32
static int SHIFT8
          Shift 8
static int XFF
          0xff
 
Fields inherited from interface org.extex.util.file.random.RandomAccessR
KILL32, X24
 
Constructor Summary
RandomAccessInputStream(java.io.InputStream iostream)
          Create a new object
 
Method Summary
 void close()
          
 byte[] getData()
          Returns the data.
 long getPointer()
          Returns the pointer in the buffer.
 boolean isEOF()
          Check, if EOF is reached.
 long length()
          
 int read()
          Reads a byte of data from this file.
 boolean readBoolean()
          
 byte readByte()
          
 int readByteAsInt()
          Reads a byte of data from this file.
 char readChar()
          Reads a Unicode character from the input.
 double readDouble()
          Reads a double from the input.
 float readFloat()
          Reads a float from the input.
 void readFully(byte[] b)
          
 void readFully(byte[] b, int off, int len)
          
 int readInt()
          Reads a signed 32-bit integer from the input.
 int readInt16()
          Reads a int with 16 bit (2x8).
 int readInt24()
          Reads a signed 24-bit integer from the input.
 int readInt8()
          Reads a int with 8 bit (1x8).
 java.lang.String readLine()
          Reads the next line of text from the input.
 long readLong()
          Reads a signed 64-bit integer from the input.
 short readShort()
          Reads a signed 16-bit number from the input.
 int readSignInt24()
          Reads a sign int with 24 bit (3x8).
 int readUnsignedByte()
          Reads an unsigned eight-bit number from the input.
 int readUnsignedShort()
          Reads an unsigned 16-bit number from the input.
 java.lang.String readUTF()
          Reads in a string from this file.
 void seek(long arg0)
          
 int skipBytes(int n)
          Attempts to skip over n bytes of input discarding the skipped bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHIFT16

public static final int SHIFT16
Shift 16

See Also:
Constant Field Values

SHIFT24

public static final int SHIFT24
Shift 24

See Also:
Constant Field Values

SHIFT32

public static final int SHIFT32
Shift 32

See Also:
Constant Field Values

SHIFT8

public static final int SHIFT8
Shift 8

See Also:
Constant Field Values

XFF

public static final int XFF
0xff

See Also:
Constant Field Values
Constructor Detail

RandomAccessInputStream

public RandomAccessInputStream(java.io.InputStream iostream)
                        throws java.io.IOException
Create a new object

Parameters:
iostream - stream for reading
Throws:
java.io.IOException - if an IO-error occured
Method Detail

close

public void close()

Specified by:
close in interface RandomAccessR
See Also:
RandomAccessR.close()

getData

public byte[] getData()
Returns the data.

Specified by:
getData in interface RandomAccessR
Returns:
the data.
See Also:
RandomAccessR.getData()

getPointer

public long getPointer()
Returns the pointer in the buffer.

Specified by:
getPointer in interface RandomAccessR
Returns:
Returns the pointer in the buffer
See Also:
RandomAccessR.getPointer()

isEOF

public boolean isEOF()
              throws java.io.IOException
Check, if EOF is reached.

Specified by:
isEOF in interface RandomAccessR
Returns:
Returns true, if EOF is reached.
Throws:
java.io.IOException - if an IO error occurs.
See Also:
RandomAccessR.isEOF()

length

public long length()

Specified by:
length in interface RandomAccessR
See Also:
RandomAccessR.length()

read

public int read()
Reads a byte of data from this file. The byte is returned as an integer in the range 0 to 255 (0x00-0xff).

Returns:
the next byte of data, or -1 if the end of the file has been reached.

readBoolean

public boolean readBoolean()
                    throws java.io.IOException

Specified by:
readBoolean in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readBoolean()

readByte

public byte readByte()
              throws java.io.IOException

Specified by:
readByte in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readByte()

readByteAsInt

public int readByteAsInt()
                  throws java.io.IOException
Reads a byte of data from this file. The byte is returned as an integer in the range 0 to 255 (0x00-0x0ff).

Specified by:
readByteAsInt in interface RandomAccessR
Returns:
the next byte of data.
Throws:
java.io.IOException - if an IO error occurs.
See Also:
RandomAccessR.readByteAsInt()

readChar

public char readChar()
              throws java.io.IOException
Reads a Unicode character from the input. If the bytes read, in order, are b1 and b2, where 0 <= b1, b2 <= 255, then the result is equal to:
     (char)((b1 << 8) | b2)
 

Specified by:
readChar in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readChar()

readDouble

public double readDouble()
                  throws java.io.IOException
Reads a double from the input.

Specified by:
readDouble in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readDouble()

readFloat

public float readFloat()
                throws java.io.IOException
Reads a float from the input.

Specified by:
readFloat in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readFloat()

readFully

public void readFully(byte[] b)
               throws java.io.IOException

Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readFully(byte[])

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws java.io.IOException

Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readFully(byte[], int, int)

readInt

public int readInt()
            throws java.io.IOException
Reads a signed 32-bit integer from the input. If the bytes read, in order, are b1, b2, b3, and b4, where 0 <= b1, b2, b3, b4 <= 255, then the result is equal to:
     (b1 << 24) | (b2 << 16) + (b3 << 8) + b4
 

Specified by:
readInt in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readInt()

readInt16

public int readInt16()
              throws java.io.IOException
Reads a int with 16 bit (2x8).

Specified by:
readInt16 in interface RandomAccessR
Returns:
Returns a int value.
Throws:
java.io.IOException - if an IO error occurs.
See Also:
RandomAccessR.readInt16()

readInt24

public int readInt24()
              throws java.io.IOException
Reads a signed 24-bit integer from the input. If the bytes read, in order, are b1, b2, and b3, where 0 <= b1, b2, b3 <= 255, then the result is equal to:
     (b1 << 16) + (b2 << 8) + b3
 

Reads a int with 24 bit (3x8).

Specified by:
readInt24 in interface RandomAccessR
Returns:
Returns a int value.
Throws:
java.io.IOException - if an IO error occurs.
See Also:
DataInput.readInt()

readInt8

public int readInt8()
             throws java.io.IOException
Reads a int with 8 bit (1x8).

Specified by:
readInt8 in interface RandomAccessR
Returns:
Returns a int value.
Throws:
java.io.IOException - if an IO error occurs.
See Also:
RandomAccessR.readInt8()

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads the next line of text from the input.

Specified by:
readLine in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readLine()

readLong

public long readLong()
              throws java.io.IOException
Reads a signed 64-bit integer from the input. If the bytes read, in order, are b1, b2, b3, b4, b5, b6, b7, and b8, where:
     0 <= b1, b2, b3, b4, b5, b6, b7, b8 <=255,
 

then the result is equal to:

     ((long)b1 << 56) + ((long)b2 << 48)
     + ((long)b3 << 40) + ((long)b4 << 32)
     + ((long)b5 << 24) + ((long)b6 << 16)
     + ((long)b7 << 8) + b8
 

Specified by:
readLong in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readLong()

readShort

public short readShort()
                throws java.io.IOException
Reads a signed 16-bit number from the input. If the two bytes read, in order, are b1 and b2, where each of the two values is between 0 and 255, inclusive, then the result is equal to:
     (short)((b1 << 8) | b2)
 

Specified by:
readShort in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readShort()

readSignInt24

public int readSignInt24()
                  throws java.io.IOException
Reads a sign int with 24 bit (3x8). The sign is calculated with the b-complement.

Specified by:
readSignInt24 in interface RandomAccessR
Returns:
Returns a int value.
Throws:
java.io.IOException - if an IO error occurs.
See Also:
RandomAccessR.readSignInt24()

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException
Reads an unsigned eight-bit number from the input.

Specified by:
readUnsignedByte in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readUnsignedByte()

readUnsignedShort

public int readUnsignedShort()
                      throws java.io.IOException
Reads an unsigned 16-bit number from the input. If the bytes read, in order, are b1 and b2, where 0 <= b1, b2 <= 255, then the result is equal to:
     (b1 << 8) | b2
 

Specified by:
readUnsignedShort in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readUnsignedShort()

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Reads in a string from this file. The string has been encoded using a modified UTF-8 format.

Specified by:
readUTF in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.readUTF()

seek

public void seek(long arg0)
          throws java.io.IOException

Specified by:
seek in interface RandomAccessR
Throws:
java.io.IOException
See Also:
RandomAccessR.seek(long)

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Attempts to skip over n bytes of input discarding the skipped bytes.

Specified by:
skipBytes in interface java.io.DataInput
Throws:
java.io.IOException
See Also:
DataInput.skipBytes(int)