Top Description Inners Fields Constructors Methods
org.apache.poi.hssf.record

public final Class RecordInputStream

extends Object
implements LittleEndianInput
Class Inheritance
All Implemented Interfaces
org.apache.poi.util.LittleEndianInput
Imports
java.io.IOException, .InputStream, java.util.Locale, org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream, org.apache.poi.hssf.record.crypto.Biff8DecryptingStream, org.apache.poi.hssf.usermodel.HSSFWorkbook, org.apache.poi.poifs.crypt.EncryptionInfo, org.apache.poi.util.IOUtils, .Internal, .LittleEndianConsts, .LittleEndianInput, .LittleEndianInputStream, .RecordFormatException

Title: Record Input Stream Description: Wraps a stream and provides helper methods for the construction of records.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
RecordInputStream.LeftoverDataException

For use in BiffViewer which may construct Records that don't completely read all available data.

private static class

Field Summary

Modifier and TypeField and Description
private final BiffHeaderInput
_bhi

Header LittleEndianInput facet of the wrapped InputStream

private int
_currentDataLength

Length of the data section of the current BIFF record (always 4 less than the total record size).

private int
_currentDataOffset

index within the data section of the current BIFF record

private int
_currentSid

the record identifier of the BIFF record currently being read

private final LittleEndianInput
_dataInput

Data LittleEndianInput facet of the wrapped InputStream

private int
_markedDataOffset

index within the data section when mark() was called

private int
_nextSid

The BIFF record identifier for the next record is read when just as the current record is finished.

private static final int
DATA_LEN_NEEDS_TO_BE_READ

When _currentDataLength has this value, it means that the previous BIFF record is finished, the next sid has been properly read, but the data size field has not been read yet.

private static final byte[]
private static final int
public static final short
MAX_RECORD_DATA_SIZE

Maximum size of a single record (minus the 4 byte header) without a continue

Constructor Summary

AccessConstructor and Description
public
public
RecordInputStream(InputStream in, EncryptionInfo key, int initialOffset)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the number of bytes available in the current BIFF record
available
()

Implements org.apache.poi.util.LittleEndianInput.available.

private void
checkRecordPosition(int requiredByteCount)

public int

Returns:

sid of next record. Can be called after hasNextRecord()
getNextSid
()

public short
public boolean

Returns:

true, if there's another record in the stream
hasNextRecord
()

Note - this method is expected to be called only when completed reading the current BIFF record.

private boolean

Returns:

true when a ContinueRecord is next.
isContinueNext
()

public boolean
public void
mark(int
the read ahead limit
readlimit
)

Mark the stream position - experimental function

public void
nextRecord()

Moves to the next record in the stream.

public int
read(byte[] b, int off, int len)

public byte[]

Returns:

all byte data for the current record
readAllContinuedRemainder
()
Deprecated POI 2.0 Best to write an 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.

public byte
readByte()

Implements org.apache.poi.util.LittleEndianInput.readByte.

Reads an 8 bit, signed value

public String
readCompressedUnicode(int requestedLength)

public double
public void
public void
readFully(byte[] buf, int off, int len)

Implements org.apache.poi.util.LittleEndianInput.readFully.

private void
readFully(byte[] buf, int off, int len, boolean isPlain)

public int
readInt()

Implements org.apache.poi.util.LittleEndianInput.readInt.

Reads a 32 bit, signed value

public long
readLong()

Implements org.apache.poi.util.LittleEndianInput.readLong.

Reads a 64 bit, signed value

private int

Returns:

the sid of the next record or INVALID_SID_VALUE if at end of stream
readNextSid
()

public void
readPlain(byte[]
the byte array to receive the bytes
buf
,
int
the start offset into the byte array
off
,
int
the amount of bytes to fill
len
)

Implements org.apache.poi.util.LittleEndianInput.readPlain.

Usually acts the same as readFully(byte[], int, int), but for an encrypted stream the raw (unencrypted) data is filled

public byte[]

Returns:

The remaining bytes of the current record.
readRemainder
()

Returns the remaining bytes for the current record.

public short
readShort()

Implements org.apache.poi.util.LittleEndianInput.readShort.

Reads a 16 bit, signed value

public String
private String
readStringCommon(int requestedLength, boolean pIsCompressedEncoding)

public int
readUByte()

Implements org.apache.poi.util.LittleEndianInput.readUByte.

Reads an 8 bit, unsigned value

public String

Returns:

the converted string
readUnicodeLEString
(int
the length of the final string
requestedLength
)

given a byte array of 16-bit unicode characters, compress to 8-bit and return a string { 0x16, 0x00 } -0x16

public int
readUShort()

Implements org.apache.poi.util.LittleEndianInput.readUShort.

Reads a 16 bit, unsigned value.

public int

Returns:

The number of bytes remaining in the current record
remaining
()

The remaining number of bytes in the current record.

public void
reset()

Resets the stream position to the previously marked position.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_bhiback to summary
private final BiffHeaderInput _bhi

Header LittleEndianInput facet of the wrapped InputStream

_currentDataLengthback to summary
private int _currentDataLength

Length of the data section of the current BIFF record (always 4 less than the total record size). When uninitialised, this field is set to DATA_LEN_NEEDS_TO_BE_READ.

_currentDataOffsetback to summary
private int _currentDataOffset

index within the data section of the current BIFF record

_currentSidback to summary
private int _currentSid

the record identifier of the BIFF record currently being read

_dataInputback to summary
private final LittleEndianInput _dataInput

Data LittleEndianInput facet of the wrapped InputStream

_markedDataOffsetback to summary
private int _markedDataOffset

index within the data section when mark() was called

_nextSidback to summary
private int _nextSid

The BIFF record identifier for the next record is read when just as the current record is finished. This field is only really valid during the time that (_currentDataLength == DATA_LEN_NEEDS_TO_BE_READ). At most other times its value is not really the 'sid of the next record'. Wwhile mid-record, this field coincidentally holds the sid of the current record.

DATA_LEN_NEEDS_TO_BE_READback to summary
private static final int DATA_LEN_NEEDS_TO_BE_READ

When _currentDataLength has this value, it means that the previous BIFF record is finished, the next sid has been properly read, but the data size field has not been read yet.

EMPTY_BYTE_ARRAYback to summary
private static final byte[] EMPTY_BYTE_ARRAY
INVALID_SID_VALUEback to summary
private static final int INVALID_SID_VALUE
MAX_RECORD_DATA_SIZEback to summary
public static final short MAX_RECORD_DATA_SIZE

Maximum size of a single record (minus the 4 byte header) without a continue

Constructor Detail

RecordInputStreamback to summary
public RecordInputStream(InputStream in) throws RecordFormatException
RecordInputStreamback to summary
public RecordInputStream(InputStream in, EncryptionInfo key, int initialOffset) throws RecordFormatException

Method Detail

availableback to summary
public int available()

Implements org.apache.poi.util.LittleEndianInput.available.

Returns:int

the number of bytes available in the current BIFF record

Annotations
@Override
See Also
remaining()
checkRecordPositionback to summary
private void checkRecordPosition(int requiredByteCount)
getNextSidback to summary
public int getNextSid()
Returns:int

sid of next record. Can be called after hasNextRecord()

getSidback to summary
public short getSid()
hasNextRecordback to summary
public boolean hasNextRecord() throws LeftoverDataException

Note - this method is expected to be called only when completed reading the current BIFF record.

Returns:boolean

true, if there's another record in the stream

Exceptions
LeftoverDataException:
if this method is called before reaching the end of the current record.
isContinueNextback to summary
private boolean isContinueNext()
Returns:boolean

true when a ContinueRecord is next.

isEncryptedback to summary
public boolean isEncrypted()
Annotations
@Internal
markback to summary
public void mark(int readlimit)

Mark the stream position - experimental function

Parameters
readlimit:int

the read ahead limit

Annotations
@Internal
See Also
InputStream#mark(int)
nextRecordback to summary
public void nextRecord() throws RecordFormatException

Moves to the next record in the stream.

Note

The auto continue flag is reset to true

readback to summary
public int read(byte[] b, int off, int len)
readAllContinuedRemainderback to summary
public byte[] readAllContinuedRemainder()

Deprecated

POI 2.0 Best to write an 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.

Returns:byte[]

all byte data for the current record

Annotations
@Deprecated
readByteback to summary
public byte readByte()

Implements org.apache.poi.util.LittleEndianInput.readByte.

Reads an 8 bit, signed value

Annotations
@Override
readCompressedUnicodeback to summary
public String readCompressedUnicode(int requestedLength)
readDoubleback to summary
public double readDouble()

Implements org.apache.poi.util.LittleEndianInput.readDouble.

Annotations
@Override
readFullyback to summary
public void readFully(byte[] buf)

Implements org.apache.poi.util.LittleEndianInput.readFully.

Annotations
@Override
readFullyback to summary
public void readFully(byte[] buf, int off, int len)

Implements org.apache.poi.util.LittleEndianInput.readFully.

Annotations
@Override
readFullyback to summary
private void readFully(byte[] buf, int off, int len, boolean isPlain)
readIntback to summary
public int readInt()

Implements org.apache.poi.util.LittleEndianInput.readInt.

Reads a 32 bit, signed value

Annotations
@Override
readLongback to summary
public long readLong()

Implements org.apache.poi.util.LittleEndianInput.readLong.

Reads a 64 bit, signed value

Annotations
@Override
readNextSidback to summary
private int readNextSid()
Returns:int

the sid of the next record or INVALID_SID_VALUE if at end of stream

readPlainback to summary
public void readPlain(byte[] buf, int off, int len)

Implements org.apache.poi.util.LittleEndianInput.readPlain.

Doc from org.apache.poi.util.LittleEndianInput.readPlain.

Usually acts the same as readFully(byte[], int, int), but for an encrypted stream the raw (unencrypted) data is filled

Parameters
buf:byte[]

the byte array to receive the bytes

off:int

the start offset into the byte array

len:int

the amount of bytes to fill

Annotations
@Override
readRemainderback to summary
public byte[] readRemainder()

Returns the remaining bytes for the current record.

Returns:byte[]

The remaining bytes of the current record.

readShortback to summary
public short readShort()

Implements org.apache.poi.util.LittleEndianInput.readShort.

Reads a 16 bit, signed value

Annotations
@Override
readStringback to summary
public String readString()
readStringCommonback to summary
private String readStringCommon(int requestedLength, boolean pIsCompressedEncoding)
readUByteback to summary
public int readUByte()

Implements org.apache.poi.util.LittleEndianInput.readUByte.

Reads an 8 bit, unsigned value

Annotations
@Override
readUnicodeLEStringback to summary
public String readUnicodeLEString(int requestedLength)

given a byte array of 16-bit unicode characters, compress to 8-bit and return a string { 0x16, 0x00 } -0x16

Parameters
requestedLength:int

the length of the final string

Returns:String

the converted string

Exceptions
IllegalArgumentException:
if len is too large (i.e., there is not enough data in string to create a String of that length)
readUShortback to summary
public int readUShort()

Implements org.apache.poi.util.LittleEndianInput.readUShort.

Reads a 16 bit, unsigned value.

Annotations
@Override
remainingback to summary
public int remaining()

The remaining number of bytes in the current record.

Returns:int

The number of bytes remaining in the current record

resetback to summary
public void reset() throws IOException

Resets the stream position to the previously marked position. Experimental function - this only works, when nextRecord() wasn't called in the meantime.

Annotations
@Internal
Exceptions
IOException:
if marking is not supported
See Also
InputStream#reset()
org.apache.poi.hssf.record back to summary

public final Class RecordInputStream.LeftoverDataException

extends RuntimeException
Class Inheritance

For use in BiffViewer which may construct Records that don't completely read all available data. This exception should never be thrown otherwise.

Constructor Summary

AccessConstructor and Description
public
LeftoverDataException(int sid, int remainingByteCount)

Method Summary

Modifier and TypeMethod and Description
private static String
getRecordName(int sid)

Constructor Detail

LeftoverDataExceptionback to summary
public LeftoverDataException(int sid, int remainingByteCount)

Method Detail

getRecordNameback to summary
private static String getRecordName(int sid)
org.apache.poi.hssf.record back to summary

private final Class RecordInputStream.SimpleHeaderInput

extends Object
implements BiffHeaderInput
Class Inheritance
  • java.lang.Object
  • org.apache.poi.hssf.record.RecordInputStream.SimpleHeaderInput
All Implemented Interfaces
org.apache.poi.hssf.record.BiffHeaderInput

Field Summary

Modifier and TypeField and Description
private final LittleEndianInput

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
public int
readDataSize()

Implements org.apache.poi.hssf.record.BiffHeaderInput.readDataSize.

Read an unsigned short from the stream without decrypting

public int
readRecordSID()

Implements org.apache.poi.hssf.record.BiffHeaderInput.readRecordSID.

Read an unsigned short from the stream without decrypting

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_leiback to summary
private final LittleEndianInput _lei

Constructor Detail

SimpleHeaderInputback to summary
private SimpleHeaderInput(LittleEndianInput lei)

Method Detail

availableback to summary
public int available()

Implements org.apache.poi.hssf.record.BiffHeaderInput.available.

Returns:int

Doc from org.apache.poi.hssf.record.BiffHeaderInput.available.

the available bytes

Annotations
@Override
readDataSizeback to summary
public int readDataSize()

Implements org.apache.poi.hssf.record.BiffHeaderInput.readDataSize.

Doc from org.apache.poi.hssf.record.BiffHeaderInput.readDataSize.

Read an unsigned short from the stream without decrypting

Returns:int

the data size

Annotations
@Override
readRecordSIDback to summary
public int readRecordSID()

Implements org.apache.poi.hssf.record.BiffHeaderInput.readRecordSID.

Doc from org.apache.poi.hssf.record.BiffHeaderInput.readRecordSID.

Read an unsigned short from the stream without decrypting

Returns:int

the record sid

Annotations
@Override