Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.derby.iapi.services.io
Class ArrayInputStream  view ArrayInputStream download ArrayInputStream.java

java.lang.Object
  extended byjava.io.InputStream
      extended byorg.apache.derby.iapi.services.io.ArrayInputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput, ErrorInfo, ErrorObjectInput, Limit, LimitObjectInput, java.io.ObjectInput

public final class ArrayInputStream
extends java.io.InputStream
implements LimitObjectInput

An InputStream that allows reading from an array of bytes. The array of bytes that is read from can be changed without having to create a new instance of this class.


Field Summary
private  int end
           
private  ErrorObjectInput oi
           
private  byte[] pageData
           
private  int position
           
private  int start
           
 
Constructor Summary
ArrayInputStream()
           
ArrayInputStream(byte[] data)
           
ArrayInputStream(byte[] data, int offset, int length)
           
 
Method Summary
 int available()
          This method returns the number of bytes that can be read without blocking.
 int clearLimit()
          Clears the limit by setting the limit to be the entire byte array.
 byte[] getData()
          Return a reference to the array of bytes this stream is going to read from so that caller may load it with stuff
 java.lang.String getErrorInfo()
           
 java.lang.Exception getNestedException()
           
 int getPosition()
           
 int read()
          This method reading a byte of data from a stream.
 int read(byte[] b, int off, int len)
          This method reads raw bytes and stores them in a byte array buffer buf starting at position offset into the buffer.
 boolean readBoolean()
          This method reads a Java boolean value from an input stream.
 byte readByte()
          This method reads a Java byte value from an input stream.
 char readChar()
          This method reads a Java char value from an input stream.
 int readCloudscapeUTF(char[][] rawData_array)
          read in a cloudscape UTF formated string into a char[].
 int readCompressedInt()
          Read a compressed int from the stream.
 long readCompressedLong()
          Read a compressed long from the stream.
 double readDouble()
          This method reads a Java double value from an input stream.
 float readFloat()
          This method reads a Java float value from an input stream.
 void readFully(byte[] b)
          This method reads raw bytes into the passed array until the array is full.
 void readFully(byte[] b, int off, int len)
          This method reads raw bytes into the passed array buf starting offset bytes into the buffer.
 int readInt()
          This method reads a Java int value from an input stream It operates by reading four bytes from the stream and converting them to a single Java int.
 java.lang.String readLine()
          This method reads the next line of text data from an input stream.
 long readLong()
          This method reads a Java long value from an input stream It operates by reading eight bytes from the stream and converting them to a single Java long.
 java.lang.Object readObject()
          Reads an object instance and returns it.
 short readShort()
          This method reads a signed 16-bit value into a Java in from the stream.
 int readUnsignedByte()
          This method reads 8 unsigned bits into a Java int value from the stream.
 int readUnsignedShort()
          This method reads 16 unsigned bits into a Java int value from the stream.
 java.lang.String readUTF()
          This method reads a String from an input stream that is encoded in a modified UTF-8 format.
 void setData(byte[] data)
          Set the array of bytes to be read.
 void setData(byte[] data, int offset, int length)
           
 void setLimit(int length)
          Set the limit of the data that can be read or written.
 int setLimit(int offset, int length)
          A setLimit which also sets the position to be offset.
 void setPosition(int newPosition)
           
 long skip(long count)
          This method causes the specified number of bytes to be read and discarded.
 int skipBytes(int n)
          This method skips and discards the specified number of bytes in an input stream.
 
Methods inherited from class java.io.InputStream
close, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.ObjectInput
close, read
 

Field Detail

pageData

private byte[] pageData

start

private int start

end

private int end

position

private int position

oi

private ErrorObjectInput oi
Constructor Detail

ArrayInputStream

public ArrayInputStream()

ArrayInputStream

public ArrayInputStream(byte[] data)

ArrayInputStream

public ArrayInputStream(byte[] data,
                        int offset,
                        int length)
                 throws java.io.IOException
Method Detail

setData

public void setData(byte[] data)
Set the array of bytes to be read.


setData

public void setData(byte[] data,
                    int offset,
                    int length)
             throws java.io.IOException

getData

public byte[] getData()
Return a reference to the array of bytes this stream is going to read from so that caller may load it with stuff


read

public int read()
         throws java.io.IOException
Description copied from interface: java.io.ObjectInput
This method reading a byte of data from a stream. It returns that byte as an int. This method blocks if no data is available to be read.

Specified by:
read in interface java.io.ObjectInput

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Description copied from interface: java.io.ObjectInput
This method reads raw bytes and stores them in a byte array buffer buf starting at position offset into the buffer. A maximum of len bytes will be read. Note that this method blocks if no data is available, but will not necessarily block until it can read len bytes of data. That is, a "short count" is possible.

Specified by:
read in interface java.io.ObjectInput

skip

public long skip(long count)
          throws java.io.IOException
Description copied from interface: java.io.ObjectInput
This method causes the specified number of bytes to be read and discarded. It is possible that fewer than the requested number of bytes will actually be skipped.

Specified by:
skip in interface java.io.ObjectInput

getPosition

public int getPosition()

setPosition

public final void setPosition(int newPosition)
                       throws java.io.IOException

available

public int available()
              throws java.io.IOException
Description copied from interface: java.io.ObjectInput
This method returns the number of bytes that can be read without blocking.

Specified by:
available in interface java.io.ObjectInput

setLimit

public int setLimit(int offset,
                    int length)
             throws java.io.IOException
A setLimit which also sets the position to be offset.


setLimit

public final void setLimit(int length)
                    throws java.io.IOException
Description copied from interface: Limit
Set the limit of the data that can be read or written. After this call up to and including length bytes can be read from or skipped in the stream.

On input classes (e.g. InputStreams) any attempt to read or skip beyond the limit will result in an end of file indication (e.g. read() methods returning -1 or throwing EOFException).

On output classes (e.g. OutputStream) any attempt to write more beyond the limit will result in an EOFException

Specified by:
setLimit in interface Limit

clearLimit

public final int clearLimit()
Clears the limit by setting the limit to be the entire byte array.

Specified by:
clearLimit in interface Limit

readFully

public final void readFully(byte[] b)
                     throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads raw bytes into the passed array until the array is full. Note that this method blocks until the data is available and throws an exception if there is not enough data left in the stream to fill the buffer. Note also that zero length buffers are permitted. In this case, the method will return immediately without reading any bytes from the stream.

Specified by:
readFully in interface java.io.DataInput

readFully

public final void readFully(byte[] b,
                            int off,
                            int len)
                     throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads raw bytes into the passed array buf starting offset bytes into the buffer. The number of bytes read will be exactly len. Note that this method blocks until the data is available and throws an exception if there is not enough data left in the stream to read len bytes. Note also that zero length buffers are permitted. In this case, the method will return immediately without reading any bytes from the stream.

Specified by:
readFully in interface java.io.DataInput

skipBytes

public final int skipBytes(int n)
                    throws java.io.IOException
Description copied from interface: java.io.DataInput
This method skips and discards the specified number of bytes in an input stream. Note that this method may skip less than the requested number of bytes. The actual number of bytes skipped is returned. No bytes are skipped if a negative number is passed to this method.

Specified by:
skipBytes in interface java.io.DataInput

readBoolean

public final boolean readBoolean()
                          throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a Java boolean value from an input stream. It does so by reading a single byte of data. If that byte is zero, then the value returned is false. If the byte is non-zero, then the value returned is true.

This method can read a boolean written by an object implementing the writeBoolean() method in the DataOutput interface.

Specified by:
readBoolean in interface java.io.DataInput

readByte

public final byte readByte()
                    throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a Java byte value from an input stream. The value is in the range of -128 to 127.

This method can read a byte written by an object implementing the writeByte() method in the DataOutput interface.

Specified by:
readByte in interface java.io.DataInput

readUnsignedByte

public final int readUnsignedByte()
                           throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads 8 unsigned bits into a Java int value from the stream. The value returned is in the range of 0 to 255.

This method can read an unsigned byte written by an object implementing the writeByte() method in the DataOutput interface.

Specified by:
readUnsignedByte in interface java.io.DataInput

readShort

public final short readShort()
                      throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a signed 16-bit value into a Java in from the stream. It operates by reading two bytes from the stream and converting them to a single 16-bit Java short. The two bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering.

As an example, if byte1 and byte2 represent the first and second byte read from the stream respectively, they will be transformed to a short in the following manner:

(short)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))

The value returned is in the range of -32768 to 32767.

This method can read a short written by an object implementing the writeShort() method in the DataOutput interface.

Specified by:
readShort in interface java.io.DataInput

readUnsignedShort

public final int readUnsignedShort()
                            throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads 16 unsigned bits into a Java int value from the stream. It operates by reading two bytes from the stream and converting them to a single Java int. The two bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering.

As an example, if byte1 and byte2 represent the first and second byte read from the stream respectively, they will be transformed to an int in the following manner:

(int)(((byte1 0xFF) << 8) + (byte2 & 0xFF))

The value returned is in the range of 0 to 65535.

This method can read an unsigned short written by an object implementing the writeShort() method in the DataOutput interface.

Specified by:
readUnsignedShort in interface java.io.DataInput

readChar

public final char readChar()
                    throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a Java char value from an input stream. It operates by reading two bytes from the stream and converting them to a single 16-bit Java char. The two bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering.

As an example, if byte1 and byte2 represent the first and second byte read from the stream respectively, they will be transformed to a char in the following manner:

(char)((byte1 << 8) + byte2)

This method can read a char written by an object implementing the writeChar() method in the DataOutput interface.

Specified by:
readChar in interface java.io.DataInput

readInt

public final int readInt()
                  throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a Java int value from an input stream It operates by reading four bytes from the stream and converting them to a single Java int. The bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering.

As an example, if byte1 through byte4 represent the first four bytes read from the stream, they will be transformed to an int in the following manner:

(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))

The value returned is in the range of -2147483648 to 2147483647.

This method can read an int written by an object implementing the writeInt() method in the DataOutput interface.

Specified by:
readInt in interface java.io.DataInput

readLong

public final long readLong()
                    throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a Java long value from an input stream It operates by reading eight bytes from the stream and converting them to a single Java long. The bytes are stored most significant byte first (i.e., "big endian") regardless of the native host byte ordering.

As an example, if byte1 through byte8 represent the first eight bytes read from the stream, they will be transformed to an long in the following manner:

(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + ((byte7 & 0xFF) << 8) + (byte8 & 0xFF)))

The value returned is in the range of -9223372036854775808 to 9223372036854775807.

This method can read an long written by an object implementing the writeLong() method in the DataOutput interface.

Specified by:
readLong in interface java.io.DataInput

readFloat

public final float readFloat()
                      throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a Java float value from an input stream. It operates by first reading an int value from the stream by calling the readInt() method in this interface, then converts that int to a float using the intBitsToFloat method in the class java.lang.Float.

This method can read a float written by an object implementing the writeFloat() method in the DataOutput interface.

Specified by:
readFloat in interface java.io.DataInput

readDouble

public final double readDouble()
                        throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a Java double value from an input stream. It operates by first reading a long value from the stream by calling the readLong() method in this interface, then converts that long to a double using the longBitsToDouble method in the class java.lang.Double.

This method can read a double written by an object implementing the writeDouble() method in the DataOutput interface.

Specified by:
readDouble in interface java.io.DataInput

readLine

public final java.lang.String readLine()
                                throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads the next line of text data from an input stream. It operates by reading bytes and converting those bytes to char values by treating the byte read as the low eight bits of the char and using 0 as the high eight bits. Because of this, it does not support the full 16-bit Unicode character set.

The reading of bytes ends when either the end of file or a line terminator is encountered. The bytes read are then returned as a String. A line terminator is a byte sequence consisting of either \r, \n or \r\n. These termination charaters are discarded and are not returned as part of the string. A line is also terminated by an end of file condition.

Specified by:
readLine in interface java.io.DataInput

readUTF

public final java.lang.String readUTF()
                               throws java.io.IOException
Description copied from interface: java.io.DataInput
This method reads a String from an input stream that is encoded in a modified UTF-8 format. This format has a leading two byte sequence that contains the remaining number of bytes to read. This two byte sequence is read using the readUnsignedShort() method of this interface. After the number of remaining bytes have been determined, these bytes are read an transformed into char values. These char values are encoded in the stream using either a one, two, or three byte format. The particular format in use can be determined by examining the first byte read.

If the first byte has a high order bit of 0, then that character consists on only one byte. This character value consists of seven bits that are at positions 0 through 6 of the byte. As an example, if byte1 is the byte read from the stream, it would be converted to a char like so:

(char)byte1

If the first byte has 110 as its high order bits, then the character consists of two bytes. The bits that make up the character value are in positions 0 through 4 of the first byte and bit positions 0 through 5 of the second byte. (The second byte should have 10 as its high order bits). These values are in most significant byte first (i.e., "big endian") order.

As an example, if byte1 and byte2 are the first two bytes read respectively, and the high order bits of them match the patterns which indicate a two byte character encoding, then they would be converted to a Java char like so:

(char)(((byte1 & 0x1F) << 6) + (byte2 & 0x3F))

If the first byte has a 1110 as its high order bits, then the character consists of three bytes. The bits that make up the character value are in positions 0 through 3 of the first byte and bit positions 0 through 5 of the other two bytes. (The second and third bytes should have 10 as their high order bits). These values are in most significant byte first (i.e., "big endian") order.

As an example, if byte1, byte2, and byte3 are the three bytes read, and the high order bits of them match the patterns which indicate a three byte character encoding, then they would be converted to a Java char like so: (char)(((byte1 & 0x0F) << 12) + ((byte2 & 0x3F) + (byte3 & 0x3F)) Note that all characters are encoded in the method that requires the fewest number of bytes with the exception of the character with the value of \<llll>u0000 which is encoded as two bytes. This is a modification of the UTF standard used to prevent C language style NUL values from appearing in the byte stream.

This method can read data that was written by an object implementing the writeUTF() method in DataOutput.

Specified by:
readUTF in interface java.io.DataInput

readCloudscapeUTF

public final int readCloudscapeUTF(char[][] rawData_array)
                            throws java.io.IOException
read in a cloudscape UTF formated string into a char[].

This routine inline's the code to read a UTF format string from a byte[] array (pageData), into a char[] array. The string will be read into the char[] array passed into this routine through rawData_array[0] if it is big enough. If it is not big enough a new char[] will be alocated and returned to the caller by putting it into rawData_array[0].

To see detailed description of the cloudscape UTF format see the writeExternal() routine of SQLChar.

The routine returns the number of char's read into the returned char[], note that this length may smaller than the actual length of the char[] array.


readCompressedInt

public final int readCompressedInt()
                            throws java.io.IOException
Read a compressed int from the stream.

Read a compressed int from the stream, which is assumed to have been written by a call to CompressNumber.writeInt().

Code from CompressedNumber is inlined here so that these fields can be read from the array with a minimum of function calls.

The format of a compressed int is as follows: Formats are (with x representing value bits):

 1 Byte- 00xxxxxx                            val <= 63 (0x3f)
 2 Byte- 01xxxxxx xxxxxxxx                   val > 63 && <= 16383 (0x3fff)
 4 byte- 1xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx val > 16383 && <= MAX_INT
 


readCompressedLong

public final long readCompressedLong()
                              throws java.io.IOException
Read a compressed long from the stream.

Read a compressed long from the stream, which is assumed to have been written by a call to CompressNumber.writeLong().

Code from CompressedNumber is inlined here so that these fields can be read from the array with a minimum of function calls.

The format of a compressed int is as follows: Formats are (with x representing value bits):

 value <= 16383 (0x3fff): 
     2 byte - 00xxxxxx xxxxxxxx 

 value > 16383 && <= 0x3fffffff:
     4 byte - 01xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx

 value > 0x3fffffff && <= MAX_LONG:
     8 byte - 1xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx
 


readObject

public java.lang.Object readObject()
                            throws java.lang.ClassNotFoundException,
                                   java.io.IOException
Description copied from interface: java.io.ObjectInput
Reads an object instance and returns it. If the class for the object being read cannot be found, then a ClassNotFoundException will be thrown.

Specified by:
readObject in interface java.io.ObjectInput

getErrorInfo

public java.lang.String getErrorInfo()
Specified by:
getErrorInfo in interface ErrorObjectInput

getNestedException

public java.lang.Exception getNestedException()
Specified by:
getNestedException in interface ErrorObjectInput