poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r722401 - in /poi/trunk/src: documentation/content/xdocs/changes.xml documentation/content/xdocs/status.xml java/org/apache/poi/hssf/dev/BiffViewer.java java/org/apache/poi/hssf/record/RecordInputStream.java
Date Tue, 02 Dec 2008 08:46:14 GMT
Author: josh
Date: Tue Dec  2 00:46:13 2008
New Revision: 722401

URL: http://svn.apache.org/viewvc?rev=722401&view=rev
Log:
Final fix for bug 44914 - Removed warning message "WARN. Unread n bytes of record 0xNN"

Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/dev/BiffViewer.java
    poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=722401&r1=722400&r2=722401&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Tue Dec  2 00:46:13 2008
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <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="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>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=722401&r1=722400&r2=722401&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Dec  2 00:46:13 2008
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <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="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>

Modified: poi/trunk/src/java/org/apache/poi/hssf/dev/BiffViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/dev/BiffViewer.java?rev=722401&r1=722400&r2=722401&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/dev/BiffViewer.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/dev/BiffViewer.java Tue Dec  2 00:46:13 2008
@@ -31,6 +31,7 @@
 import java.util.List;
 
 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.pivottable.*;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -63,7 +64,19 @@
 		List<Record> temp = new ArrayList<Record>();
 
 		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();
 			if (recStream.getSid() == 0) {
 				continue;

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java?rev=722401&r1=722400&r2=722401&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecordInputStream.java Tue Dec  2 00:46:13
2008
@@ -20,6 +20,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 
+import org.apache.poi.hssf.dev.BiffViewer;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.LittleEndianInputStream;
@@ -40,6 +41,17 @@
 	 */
 	private static final int DATA_LEN_NEEDS_TO_BE_READ = -1;
 	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} */
 	private final LittleEndianInput _le;
@@ -102,17 +114,14 @@
 	}
 
 	/**
-	 * Note - this method is expected to be called only when completed reading the current BIFF
record.
-	 * Calling this before reaching the end of the current record will cause all remaining data
to be
-	 * discarded
+	 * Note - this method is expected to be called only when completed reading the current BIFF

+	 * record.
+	 * @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) {
-			System.out.println("WARN. Unread "+remaining()+" bytes of record 0x"+Integer.toHexString(_currentSid));
-			// discard unread data
-			while (_currentDataOffset < _currentDataLength) {
-				readByte();
-			}
+			throw new LeftoverDataException(_currentSid, remaining());
 		}
 		if (_currentDataLength != DATA_LEN_NEEDS_TO_BE_READ) {
 			_nextSid = readNextSid();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message