org.apache.derby.iapi.services.io
Class ArrayInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byorg.apache.derby.iapi.services.io.ArrayInputStream
All Implemented Interfaces:
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
           
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
ArrayInputStream()
           
ArrayInputStream(byte[] data)
           
ArrayInputStream(byte[] data, int offset, int length)
           
 
Method Summary
 int available()
           
 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()
           
 int read(byte[] b, int off, int len)
           
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 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()
           
 float readFloat()
           
 void readFully(byte[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 java.lang.String readLine()
           
 long readLong()
           
 java.lang.Object readObject()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 java.lang.String readUTF()
           
 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)
           
 int skipBytes(int n)
           
 
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
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
Specified by:
read in interface java.io.ObjectInput
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Specified by:
read in interface java.io.ObjectInput
Throws:
java.io.IOException

skip

public long skip(long count)
          throws java.io.IOException
Specified by:
skip in interface java.io.ObjectInput
Throws:
java.io.IOException

getPosition

public int getPosition()

setPosition

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

available

public int available()
              throws java.io.IOException
Specified by:
available in interface java.io.ObjectInput
Throws:
java.io.IOException

setLimit

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

Throws:
java.io.IOException - limit is out of range

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
Throws:
java.io.IOException - IOException from some underlying stream

clearLimit

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

Specified by:
clearLimit in interface Limit
Returns:
the number of bytes within the limit that have not been read or written.
See Also:
Limit.clearLimit()

readFully

public final void readFully(byte[] b)
                     throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

readFully

public final void readFully(byte[] b,
                            int off,
                            int len)
                     throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

skipBytes

public final int skipBytes(int n)
                    throws java.io.IOException
Specified by:
skipBytes in interface java.io.DataInput
Throws:
java.io.IOException

readBoolean

public final boolean readBoolean()
                          throws java.io.IOException
Specified by:
readBoolean in interface java.io.DataInput
Throws:
java.io.IOException

readByte

public final byte readByte()
                    throws java.io.IOException
Specified by:
readByte in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedByte

public final int readUnsignedByte()
                           throws java.io.IOException
Specified by:
readUnsignedByte in interface java.io.DataInput
Throws:
java.io.IOException

readShort

public final short readShort()
                      throws java.io.IOException
Specified by:
readShort in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedShort

public final int readUnsignedShort()
                            throws java.io.IOException
Specified by:
readUnsignedShort in interface java.io.DataInput
Throws:
java.io.IOException

readChar

public final char readChar()
                    throws java.io.IOException
Specified by:
readChar in interface java.io.DataInput
Throws:
java.io.IOException

readInt

public final int readInt()
                  throws java.io.IOException
Specified by:
readInt in interface java.io.DataInput
Throws:
java.io.IOException

readLong

public final long readLong()
                    throws java.io.IOException
Specified by:
readLong in interface java.io.DataInput
Throws:
java.io.IOException

readFloat

public final float readFloat()
                      throws java.io.IOException
Specified by:
readFloat in interface java.io.DataInput
Throws:
java.io.IOException

readDouble

public final double readDouble()
                        throws java.io.IOException
Specified by:
readDouble in interface java.io.DataInput
Throws:
java.io.IOException

readLine

public final java.lang.String readLine()
                                throws java.io.IOException
Specified by:
readLine in interface java.io.DataInput
Throws:
java.io.IOException

readUTF

public final java.lang.String readUTF()
                               throws java.io.IOException
Specified by:
readUTF in interface java.io.DataInput
Throws:
java.io.IOException

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.

Parameters:
rawData_array - This parameter uses a element array to implement an in/out function parameter. The char[] array in rawData_array[0] is used to read the data into unless it is not big enough, then a new array is allocated and the old one discarded. In either case on return rawData_array[0] contains the filled in char[] - caller must allow that the array may or may not be different from the one passed in.
Returns:
The the number of valid char's in the returned char[].
Throws:
StandardException - Standard exception policy.
java.io.IOException

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
 

Throws:
StandardException - Standard exception policy.
java.io.IOException

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
 

Throws:
java.io.IOException

readObject

public java.lang.Object readObject()
                            throws java.lang.ClassNotFoundException,
                                   java.io.IOException
Specified by:
readObject in interface java.io.ObjectInput
Throws:
java.lang.ClassNotFoundException
java.io.IOException

getErrorInfo

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

getNestedException

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

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.