Package org.apache.poi.hssf.record
Class RecordInputStream
- java.lang.Object
-
- org.apache.poi.hssf.record.RecordInputStream
-
- All Implemented Interfaces:
LittleEndianInput
public final class RecordInputStream extends Object implements LittleEndianInput
Title: Record Input Stream Description: Wraps a stream and provides helper methods for the construction of records.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRecordInputStream.LeftoverDataExceptionFor use in BiffViewer which may constructRecords that don't completely read all available data.
-
Field Summary
Fields Modifier and Type Field Description static shortMAX_RECORD_DATA_SIZEMaximum size of a single record (minus the 4 byte header) without a continue
-
Constructor Summary
Constructors Constructor Description RecordInputStream(InputStream in)RecordInputStream(InputStream in, EncryptionInfo key, int initialOffset)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intavailable()intgetNextSid()shortgetSid()booleanhasNextRecord()Note - this method is expected to be called only when completed reading the current BIFF record.booleanisEncrypted()voidmark(int readlimit)Mark the stream position - experimental functionvoidnextRecord()Moves to the next record in the stream.intread(byte[] b, int off, int len)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.bytereadByte()Reads an 8 bit, signed valueStringreadCompressedUnicode(int requestedLength)doublereadDouble()voidreadFully(byte[] buf)voidreadFully(byte[] buf, int off, int len)intreadInt()Reads a 32 bit, signed valuelongreadLong()Reads a 64 bit, signed valuevoidreadPlain(byte[] buf, int off, int len)Usually acts the same asLittleEndianInput.readFully(byte[], int, int), but for an encrypted stream the raw (unencrypted) data is filledbyte[]readRemainder()Returns the remaining bytes for the current record.shortreadShort()Reads a 16 bit, signed valueStringreadString()intreadUByte()Reads an 8 bit, unsigned valueStringreadUnicodeLEString(int requestedLength)given a byte array of 16-bit unicode characters, compress to 8-bit and return a string { 0x16, 0x00 } -0x16intreadUShort()Reads a 16 bit, unsigned value.intremaining()The remaining number of bytes in the current record.voidreset()Resets the stream position to the previously marked position.
-
-
-
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
-
-
Constructor Detail
-
RecordInputStream
public RecordInputStream(InputStream in) throws RecordFormatException
- Throws:
RecordFormatException
-
RecordInputStream
public RecordInputStream(InputStream in, EncryptionInfo key, int initialOffset) throws RecordFormatException
- Throws:
RecordFormatException
-
-
Method Detail
-
available
public int available()
- Specified by:
availablein interfaceLittleEndianInput- Returns:
- the number of bytes available in the current BIFF record
- See Also:
remaining()
-
read
public int read(byte[] b, int off, int len)
-
getSid
public short getSid()
-
hasNextRecord
public boolean hasNextRecord() throws RecordInputStream.LeftoverDataExceptionNote - this method is expected to be called only when completed reading the current BIFF record.- Returns:
- true, if there's another record in the stream
- Throws:
RecordInputStream.LeftoverDataException- if this method is called before reaching the end of the current record.
-
nextRecord
public void nextRecord() throws RecordFormatExceptionMoves to the next record in the stream. Note: The auto continue flag is reset to true- Throws:
RecordFormatException
-
readByte
public byte readByte()
Reads an 8 bit, signed value- Specified by:
readBytein interfaceLittleEndianInput
-
readShort
public short readShort()
Reads a 16 bit, signed value- Specified by:
readShortin interfaceLittleEndianInput
-
readInt
public int readInt()
Reads a 32 bit, signed value- Specified by:
readIntin interfaceLittleEndianInput
-
readLong
public long readLong()
Reads a 64 bit, signed value- Specified by:
readLongin interfaceLittleEndianInput
-
readUByte
public int readUByte()
Reads an 8 bit, unsigned value- Specified by:
readUBytein interfaceLittleEndianInput
-
readUShort
public int readUShort()
Reads a 16 bit, unsigned value.- Specified by:
readUShortin interfaceLittleEndianInput
-
readDouble
public double readDouble()
- Specified by:
readDoublein interfaceLittleEndianInput
-
readPlain
public void readPlain(byte[] buf, int off, int len)Description copied from interface:LittleEndianInputUsually acts the same asLittleEndianInput.readFully(byte[], int, int), but for an encrypted stream the raw (unencrypted) data is filled- Specified by:
readPlainin interfaceLittleEndianInput- Parameters:
buf- the byte array to receive the bytesoff- the start offset into the byte arraylen- the amount of bytes to fill
-
readFully
public void readFully(byte[] buf)
- Specified by:
readFullyin interfaceLittleEndianInput
-
readFully
public void readFully(byte[] buf, int off, int len)- Specified by:
readFullyin interfaceLittleEndianInput
-
readString
public String readString()
-
readUnicodeLEString
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- the length of the final string- Returns:
- the converted string
- Throws:
IllegalArgumentException- if len is too large (i.e., there is not enough data in string to create a String of that length)
-
readCompressedUnicode
public String readCompressedUnicode(int requestedLength)
-
readRemainder
public byte[] readRemainder()
Returns the remaining bytes for the current record.- Returns:
- The remaining bytes of the current record.
-
readAllContinuedRemainder
@Deprecated 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:
- all byte data for the current record
-
remaining
public int remaining()
The remaining number of bytes in the current record.- Returns:
- The number of bytes remaining in the current record
-
getNextSid
public int getNextSid()
- Returns:
- sid of next record. Can be called after hasNextRecord()
-
mark
@Internal public void mark(int readlimit)
Mark the stream position - experimental function- Parameters:
readlimit- the read ahead limit- See Also:
InputStream.mark(int)
-
reset
@Internal 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.- Throws:
IOException- if marking is not supported- See Also:
InputStream.reset()
-
isEncrypted
@Internal public boolean isEncrypted()
-
-