| Method from org.apache.poi.hssf.record.RecordInputStream Detail: |
protected void checkRecordPosition() {
if (remaining() < = 0) {
if (isContinueNext() && autoContinue) {
nextRecord();
}
else throw new ArrayIndexOutOfBoundsException();
}
}
|
public boolean getAutoContinue() {
return autoContinue;
}
|
public short getLength() {
return currentLength;
}
|
public byte[] getNANData() {
if (NAN_data == null)
throw new RecordFormatException("Do NOT call getNANData without calling readDouble that returns NaN");
return NAN_data;
}
|
public long getPos() {
return pos;
}
|
public short getRecordOffset() {
return recordOffset;
}
|
public short getSid() {
return currentSid;
}
|
public boolean hasNextRecord() {
return (nextSid != 0);
}
|
public boolean isContinueNext() {
return (nextSid == ContinueRecord.sid);
}
Returns true iif a Continue record is next in the excel stream |
public void nextRecord() throws RecordFormatException {
if ((currentLength != -1) && (currentLength != recordOffset)) {
System.out.println("WARN. Unread "+remaining()+" bytes of record 0x"+Integer.toHexString(currentSid));
}
currentSid = nextSid;
pos += LittleEndian.SHORT_SIZE;
autoContinue = true;
try {
recordOffset = 0;
currentLength = LittleEndian.readShort(in);
if (currentLength > MAX_RECORD_DATA_SIZE)
throw new RecordFormatException("The content of an excel record cannot exceed "+MAX_RECORD_DATA_SIZE+" bytes");
pos += LittleEndian.SHORT_SIZE;
in.read(data, 0, currentLength);
//Read the Sid of the next record
nextSid = LittleEndian.readShort(in);
} catch (IOException ex) {
throw new RecordFormatException("Error reading bytes", ex);
}
}
Moves to the next record in the stream.
Note: The auto continue flag is reset to true |
public int read() throws IOException {
checkRecordPosition();
byte result = data[recordOffset];
recordOffset += 1;
pos += 1;
return result;
}
This method will read a byte from the current record |
public byte[] readAllContinuedRemainder() {
//Using a ByteArrayOutputStream is just an easy way to get a
//growable array of the data.
ByteArrayOutputStream out = new ByteArrayOutputStream(2*MAX_RECORD_DATA_SIZE);
while (isContinueNext()) {
byte[] b = readRemainder();
out.write(b, 0, b.length);
nextRecord();
}
byte[] b = readRemainder();
out.write(b, 0, b.length);
return out.toByteArray();
} 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. |
public byte readByte() {
checkRecordPosition();
byte result = data[recordOffset];
recordOffset += 1;
pos += 1;
return result;
}
Reads an 8 bit, signed value |
public String readCompressedUnicode(int length) {
if(length == 0) {
return "";
}
if ((length < 0) || ((remaining() < length) && !isContinueNext())) {
throw new IllegalArgumentException("Illegal length " + length);
}
StringBuffer buf = new StringBuffer(length);
for (int i=0;i< length;i++) {
if ((remaining() == 0) && (isContinueNext())) {
nextRecord();
int compressByte = readByte();
if(compressByte != 0) throw new IllegalArgumentException("compressByte in continue records must be 0 while reading compressed unicode");
}
byte b = readByte();
//Typecast direct to char from byte with high bit set causes all ones
//in the high byte of the char (which is of course incorrect)
char ch = (char)( (short)0xff & (short)b );
buf.append(ch);
}
return buf.toString();
}
|
public double readDouble() {
checkRecordPosition();
//Reset NAN data
NAN_data = null;
double result = LittleEndian.getDouble(data, recordOffset);
//Excel represents NAN in several ways, at this point in time we do not often
//know the sequence of bytes, so as a hack we store the NAN byte sequence
//so that it is not corrupted.
if (Double.isNaN(result)) {
NAN_data = new byte[8];
System.arraycopy(data, recordOffset, NAN_data, 0, 8);
}
recordOffset += LittleEndian.DOUBLE_SIZE;
pos += LittleEndian.DOUBLE_SIZE;
return result;
}
|
public int readInt() {
checkRecordPosition();
int result = LittleEndian.getInt(data, recordOffset);
recordOffset += LittleEndian.INT_SIZE;
pos += LittleEndian.INT_SIZE;
return result;
}
|
public long readLong() {
checkRecordPosition();
long result = LittleEndian.getLong(data, recordOffset);
recordOffset += LittleEndian.LONG_SIZE;
pos += LittleEndian.LONG_SIZE;
return result;
}
|
public byte[] readRemainder() {
int size = remaining();
byte[] result = new byte[size];
System.arraycopy(data, recordOffset, result, 0, size);
recordOffset += size;
pos += size;
return result;
}
Returns the remaining bytes for the current record. |
public short readShort() {
checkRecordPosition();
short result = LittleEndian.getShort(data, recordOffset);
recordOffset += LittleEndian.SHORT_SIZE;
pos += LittleEndian.SHORT_SIZE;
return result;
}
Reads a 16 bit, signed value |
public short[] readShortArray() {
checkRecordPosition();
short[] arr = LittleEndian.getShortArray(data, recordOffset);
final int size = (2 * (arr.length +1));
recordOffset += size;
pos += size;
return arr;
}
|
public short readUByte() {
short s = readByte();
if(s < 0) {
s += 256;
}
return s;
}
Reads an 8 bit, unsigned value |
public int readUShort() {
checkRecordPosition();
int result = LittleEndian.getUShort(data, recordOffset);
recordOffset += LittleEndian.SHORT_SIZE;
pos += LittleEndian.SHORT_SIZE;
return result;
}
Reads a 16 bit,un- signed value. |
public String readUnicodeLEString(int length) {
if ((length < 0) || (((remaining() / 2) < length) && !isContinueNext())) {
throw new IllegalArgumentException("Illegal length - asked for " + length + " but only " + (remaining()/2) + " left!");
}
StringBuffer buf = new StringBuffer(length);
for (int i=0;i< length;i++) {
if ((remaining() == 0) && (isContinueNext())){
nextRecord();
int compressByte = readByte();
if(compressByte != 1) throw new IllegalArgumentException("compressByte in continue records must be 1 while reading unicode LE string");
}
char ch = (char)readShort();
buf.append(ch);
}
return buf.toString();
}
given a byte array of 16-bit unicode characters, compress to 8-bit and
return a string
{ 0x16, 0x00 } -0x16 |
public UnicodeString readUnicodeString() {
return new UnicodeString(this);
}
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. |
public int remaining() {
return (currentLength - recordOffset);
}
The remaining number of bytes in the current record. |
public void setAutoContinue(boolean enable) {
this.autoContinue = enable;
}
|