public static final class LeftoverDataException extends RuntimeException {
public LeftoverDataException(int sid, int remainingByteCount) {
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.");
}
+
+ 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} */
String actual = in.readString();
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);
+ }
}