Methods Summary |
---|
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()Returns true iif a Continue record is next in the excel stream
return (nextSid == ContinueRecord.sid);
|
public void | nextRecord()Moves to the next record in the stream.
Note: The auto continue flag is reset to true
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);
}
|
public int | read()This method will read a byte from the current record
checkRecordPosition();
byte result = data[recordOffset];
recordOffset += 1;
pos += 1;
return result;
|
public byte[] | readAllContinuedRemainder()Reads all byte data for the current record, including any
that overlaps into any following continue records.
//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();
|
public byte | readByte()
checkRecordPosition();
byte result = data[recordOffset];
recordOffset += 1;
pos += 1;
return result;
|
public java.lang.String | readCompressedUnicode(int length)
if ((length < 0) || (remaining() < length)) {
throw new IllegalArgumentException("Illegal length");
}
StringBuffer buf = new StringBuffer(length);
for (int i=0;i<length;i++) {
if ((remaining() == 0) && (isContinueNext()))
nextRecord();
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()Returns the remaining bytes for the current record.
int size = remaining();
byte[] result = new byte[size];
System.arraycopy(data, recordOffset, result, 0, size);
recordOffset += size;
pos += size;
return result;
|
public short | readShort()
checkRecordPosition();
short result = LittleEndian.getShort(data, recordOffset);
recordOffset += LittleEndian.SHORT_SIZE;
pos += LittleEndian.SHORT_SIZE;
return result;
|
public short[] | readShortArray()
checkRecordPosition();
short[] arr = LittleEndian.getShortArray(data, recordOffset);
final int size = (2 * (arr.length +1));
recordOffset += size;
pos += size;
return arr;
|
public int | readUShort()
checkRecordPosition();
int result = LittleEndian.getUShort(data, recordOffset);
recordOffset += LittleEndian.SHORT_SIZE;
pos += LittleEndian.SHORT_SIZE;
return result;
|
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
if ((length < 0) || (((remaining() / 2) < length) && !isContinueNext())) {
throw new IllegalArgumentException("Illegal length");
}
StringBuffer buf = new StringBuffer(length);
for (int i=0;i<length;i++) {
if ((remaining() == 0) && (isContinueNext()))
nextRecord();
char ch = (char)readShort();
buf.append(ch);
}
return buf.toString();
|
public org.apache.poi.hssf.record.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.
return new UnicodeString(this);
|
public int | remaining()The remaining number of bytes in the current record.
return (currentLength - recordOffset);
|
public void | setAutoContinue(boolean enable)
this.autoContinue = enable;
|