org.apache.poi.hssf.record
Class RecordInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.apache.poi.hssf.record.RecordInputStream
All Implemented Interfaces:
java.io.Closeable

public class RecordInputStream
extends java.io.InputStream

Title: Record Input Stream

Description: Wraps a stream and provides helper methods for the construction of records.

Author:
Jason Height (jheight @ apache dot org)

Field Summary
protected  short currentLength
           
protected  short currentSid
           
protected  byte[] data
           
static short MAX_RECORD_DATA_SIZE
          Maximum size of a single record (minus the 4 byte header) without a continue
protected  short nextSid
           
protected  long pos
           
protected  short recordOffset
           
 
Constructor Summary
RecordInputStream(java.io.InputStream in)
           
 
Method Summary
protected  void checkRecordPosition()
           
 boolean getAutoContinue()
           
 short getLength()
           
 byte[] getNANData()
           
 long getPos()
           
 short getRecordOffset()
           
 short getSid()
           
 boolean hasNextRecord()
           
 boolean isContinueNext()
          Returns true iif a Continue record is next in the excel stream
 void nextRecord()
          Moves to the next record in the stream.
 int read()
          This method will read a byte from the current record
 byte[] readAllContinuedRemainder()
          Deprecated. Best to write a input stream that wraps this one where there is special sub record that may overlap continue records.
 byte readByte()
          Reads an 8 bit, signed value
 java.lang.String readCompressedUnicode(int length)
           
 double readDouble()
           
 int readInt()
           
 long readLong()
           
 byte[] readRemainder()
          Returns the remaining bytes for the current record.
 short readShort()
          Reads a 16 bit, signed value
 short[] readShortArray()
           
 short readUByte()
          Reads an 8 bit, unsigned value
 java.lang.String readUnicodeLEString(int length)
          given a byte array of 16-bit unicode characters, compress to 8-bit and return a string { 0x16, 0x00 } -0x16
 UnicodeString readUnicodeString()
          Returns an excel style unicode string from the bytes reminaing in the record.
 int readUShort()
          Reads a 16 bit,un- signed value.
 int remaining()
          The remaining number of bytes in the current record.
 void setAutoContinue(boolean enable)
           
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_RECORD_DATA_SIZE

public static final short MAX_RECORD_DATA_SIZE
Maximum size of a single record (minus the 4 byte header) without a continue

See Also:
Constant Field Values

currentSid

protected short currentSid

currentLength

protected short currentLength

nextSid

protected short nextSid

data

protected byte[] data

recordOffset

protected short recordOffset

pos

protected long pos
Constructor Detail

RecordInputStream

public RecordInputStream(java.io.InputStream in)
                  throws RecordFormatException
Throws:
RecordFormatException
Method Detail

read

public int read()
         throws java.io.IOException
This method will read a byte from the current record

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

getSid

public short getSid()

getLength

public short getLength()

getRecordOffset

public short getRecordOffset()

getPos

public long getPos()

hasNextRecord

public boolean hasNextRecord()

nextRecord

public void nextRecord()
                throws RecordFormatException
Moves to the next record in the stream. Note: The auto continue flag is reset to true

Throws:
RecordFormatException

setAutoContinue

public void setAutoContinue(boolean enable)

getAutoContinue

public boolean getAutoContinue()

checkRecordPosition

protected void checkRecordPosition()

readByte

public byte readByte()
Reads an 8 bit, signed value


readShort

public short readShort()
Reads a 16 bit, signed value


readInt

public int readInt()

readLong

public long readLong()

readUByte

public short readUByte()
Reads an 8 bit, unsigned value


readUShort

public int readUShort()
Reads a 16 bit,un- signed value.

Returns:

readDouble

public double readDouble()

getNANData

public byte[] getNANData()

readShortArray

public short[] readShortArray()

readUnicodeLEString

public java.lang.String readUnicodeLEString(int length)
given a byte array of 16-bit unicode characters, compress to 8-bit and return a string { 0x16, 0x00 } -0x16

Parameters:
length - the length of the final string
Returns:
the converted string
Throws:
java.lang.IllegalArgumentException - if len is too large (i.e., there is not enough data in string to create a String of that length)

readCompressedUnicode

public java.lang.String readCompressedUnicode(int length)

readUnicodeString

public UnicodeString readUnicodeString()
Returns an excel style unicode string from the bytes reminaing in the record. Note: Unicode strings differ from normal strings due to the addition of formatting information.

Returns:
The unicode string representation of the remaining bytes.

readRemainder

public byte[] readRemainder()
Returns the remaining bytes for the current record.

Returns:
The remaining bytes of the current record.

readAllContinuedRemainder

public byte[] readAllContinuedRemainder()
Deprecated. Best to write a input stream that wraps this one where there is special sub record that may overlap continue records.

Reads all byte data for the current record, including any that overlaps into any following continue records.


remaining

public int remaining()
The remaining number of bytes in the current record.

Returns:
The number of bytes remaining in the current record

isContinueNext

public boolean isContinueNext()
Returns true iif a Continue record is next in the excel stream

Returns:
True when a ContinueRecord is next.


Copyright 2008 The Apache Software Foundation or its licensors, as applicable.