mirror of https://github.com/apache/poi.git
Final fix for bug 44914 - Removed warning message "WARN. Unread n bytes of record 0xNN"
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@722401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e8a4df9090
commit
67653ff822
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.5-beta5" date="2008-??-??">
|
<release version="3.5-beta5" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">44914 - Fixed warning message "WARN. Unread n bytes of record 0xNN"</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">46156 - Improved number to text conversion to be closer to that of Excel</action>
|
<action dev="POI-DEVELOPERS" type="add">46156 - Improved number to text conversion to be closer to that of Excel</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">46312 - Fixed ValueRecordsAggregate to handle removal of new empty row</action>
|
<action dev="POI-DEVELOPERS" type="fix">46312 - Fixed ValueRecordsAggregate to handle removal of new empty row</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">46269 - Improved error message when attempting to read BIFF2 file</action>
|
<action dev="POI-DEVELOPERS" type="add">46269 - Improved error message when attempting to read BIFF2 file</action>
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.5-beta5" date="2008-??-??">
|
<release version="3.5-beta5" date="2008-??-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">44914 - Fixed warning message "WARN. Unread n bytes of record 0xNN"</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">46156 - Improved number to text conversion to be closer to that of Excel</action>
|
<action dev="POI-DEVELOPERS" type="add">46156 - Improved number to text conversion to be closer to that of Excel</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">46312 - Fixed ValueRecordsAggregate to handle removal of new empty row</action>
|
<action dev="POI-DEVELOPERS" type="fix">46312 - Fixed ValueRecordsAggregate to handle removal of new empty row</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">46269 - Improved error message when attempting to read BIFF2 file</action>
|
<action dev="POI-DEVELOPERS" type="add">46269 - Improved error message when attempting to read BIFF2 file</action>
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.*;
|
import org.apache.poi.hssf.record.*;
|
||||||
|
import org.apache.poi.hssf.record.RecordInputStream.LeftoverDataException;
|
||||||
import org.apache.poi.hssf.record.chart.*;
|
import org.apache.poi.hssf.record.chart.*;
|
||||||
import org.apache.poi.hssf.record.pivottable.*;
|
import org.apache.poi.hssf.record.pivottable.*;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
|
@ -63,7 +64,19 @@ public final class BiffViewer {
|
||||||
List<Record> temp = new ArrayList<Record>();
|
List<Record> temp = new ArrayList<Record>();
|
||||||
|
|
||||||
RecordInputStream recStream = new RecordInputStream(is);
|
RecordInputStream recStream = new RecordInputStream(is);
|
||||||
while (recStream.hasNextRecord()) {
|
while (true) {
|
||||||
|
boolean hasNext;
|
||||||
|
try {
|
||||||
|
hasNext = recStream.hasNextRecord();
|
||||||
|
} catch (LeftoverDataException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println("Discarding " + recStream.remaining() + " bytes and continuing");
|
||||||
|
recStream.readRemainder();
|
||||||
|
hasNext = recStream.hasNextRecord();
|
||||||
|
}
|
||||||
|
if (!hasNext) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
recStream.nextRecord();
|
recStream.nextRecord();
|
||||||
if (recStream.getSid() == 0) {
|
if (recStream.getSid() == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.poi.hssf.record;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.dev.BiffViewer;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.LittleEndianInput;
|
import org.apache.poi.util.LittleEndianInput;
|
||||||
import org.apache.poi.util.LittleEndianInputStream;
|
import org.apache.poi.util.LittleEndianInputStream;
|
||||||
|
@ -41,6 +42,17 @@ public final class RecordInputStream extends InputStream implements LittleEndian
|
||||||
private static final int DATA_LEN_NEEDS_TO_BE_READ = -1;
|
private static final int DATA_LEN_NEEDS_TO_BE_READ = -1;
|
||||||
private static final byte[] EMPTY_BYTE_ARRAY = { };
|
private static final byte[] EMPTY_BYTE_ARRAY = { };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For use in {@link BiffViewer} which may construct {@link Record}s that don't completely
|
||||||
|
* read all available data. This exception should never be thrown otherwise.
|
||||||
|
*/
|
||||||
|
public static final class LeftoverDataException extends RuntimeException {
|
||||||
|
public LeftoverDataException(int sid, int remainingByteCount) {
|
||||||
|
super("Initialisation of record 0x" + Integer.toHexString(sid).toUpperCase()
|
||||||
|
+ " left " + remainingByteCount + " bytes remaining still to be read.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** {@link LittleEndianInput} facet of the wrapped {@link InputStream} */
|
/** {@link LittleEndianInput} facet of the wrapped {@link InputStream} */
|
||||||
private final LittleEndianInput _le;
|
private final LittleEndianInput _le;
|
||||||
/** the record identifier of the BIFF record currently being read */
|
/** the record identifier of the BIFF record currently being read */
|
||||||
|
@ -102,17 +114,14 @@ public final class RecordInputStream extends InputStream implements LittleEndian
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note - this method is expected to be called only when completed reading the current BIFF record.
|
* Note - this method is expected to be called only when completed reading the current BIFF
|
||||||
* Calling this before reaching the end of the current record will cause all remaining data to be
|
* record.
|
||||||
* discarded
|
* @throws LeftoverDataException if this method is called before reaching the end of the
|
||||||
|
* current record.
|
||||||
*/
|
*/
|
||||||
public boolean hasNextRecord() {
|
public boolean hasNextRecord() throws LeftoverDataException {
|
||||||
if (_currentDataLength != -1 && _currentDataLength != _currentDataOffset) {
|
if (_currentDataLength != -1 && _currentDataLength != _currentDataOffset) {
|
||||||
System.out.println("WARN. Unread "+remaining()+" bytes of record 0x"+Integer.toHexString(_currentSid));
|
throw new LeftoverDataException(_currentSid, remaining());
|
||||||
// discard unread data
|
|
||||||
while (_currentDataOffset < _currentDataLength) {
|
|
||||||
readByte();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (_currentDataLength != DATA_LEN_NEEDS_TO_BE_READ) {
|
if (_currentDataLength != DATA_LEN_NEEDS_TO_BE_READ) {
|
||||||
_nextSid = readNextSid();
|
_nextSid = readNextSid();
|
||||||
|
|
Loading…
Reference in New Issue