Fixup printing record name in case of unknown sid

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1691312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-07-16 03:49:44 +00:00
parent da41662294
commit 8d8141ad7f
2 changed files with 17 additions and 1 deletions

View File

@ -52,9 +52,17 @@ public final class RecordInputStream implements LittleEndianInput {
public static final class LeftoverDataException extends RuntimeException { public static final class LeftoverDataException extends RuntimeException {
public LeftoverDataException(int sid, int remainingByteCount) { public LeftoverDataException(int sid, int remainingByteCount) {
super("Initialisation of record 0x" + Integer.toHexString(sid).toUpperCase() super("Initialisation of record 0x" + Integer.toHexString(sid).toUpperCase()
+ "(" + RecordFactory.getRecordClass(sid).getSimpleName() + ") left " + remainingByteCount + "(" + getRecordName(sid) + ") left " + remainingByteCount
+ " bytes remaining still to be read."); + " bytes remaining still to be read.");
} }
private static String getRecordName(int sid) {
Class<? extends Record> recordClass = RecordFactory.getRecordClass(sid);
if(recordClass == null) {
return null;
}
return recordClass.getSimpleName();
}
} }
/** Header {@link LittleEndianInput} facet of the wrapped {@link InputStream} */ /** Header {@link LittleEndianInput} facet of the wrapped {@link InputStream} */

View File

@ -94,4 +94,12 @@ public final class TestRecordInputStream extends TestCase {
String actual = in.readString(); String actual = in.readString();
assertEquals("Multilingual - \u591A\u8A00\u8A9E", actual); assertEquals("Multilingual - \u591A\u8A00\u8A9E", actual);
} }
public void testLeftoverDataException() {
// just ensure that the exception is created correctly, even with unknown sids
new RecordInputStream.LeftoverDataException(1, 200);
new RecordInputStream.LeftoverDataException(0, 200);
new RecordInputStream.LeftoverDataException(999999999, 200);
new RecordInputStream.LeftoverDataException(HeaderRecord.sid, 200);
}
} }