Fix java.nio.BufferUnderflowException

This commit is contained in:
Him188 2019-12-15 15:53:29 +08:00
parent f771077572
commit 1aafe78b77

View File

@ -67,7 +67,7 @@ fun Input.readTLVMap(expectingEOF: Boolean = false, tagSize: Int = 1): MutableMa
2 -> readUShort() 2 -> readUShort()
else -> error("Unsupported tag size: $tagSize") else -> error("Unsupported tag size: $tagSize")
} }
} catch (e: EOFException) { } catch (e: Exception) { // java.nio.BufferUnderflowException is not a EOFException...
if (expectingEOF) { if (expectingEOF) {
return map return map
} }
@ -79,7 +79,7 @@ fun Input.readTLVMap(expectingEOF: Boolean = false, tagSize: Int = 1): MutableMa
check(!map.containsKey(type.toUInt())) { check(!map.containsKey(type.toUInt())) {
"Count not readTLVMap: duplicated key 0x${type.toUInt().toUHexString("")}. " + "Count not readTLVMap: duplicated key 0x${type.toUInt().toUHexString("")}. " +
"map=$map" + "map=$map" +
", duplicating value=${this.readUShortLVByteArray()}" + ", duplicating value=${this.readUShortLVByteArray().toUHexString()}" +
", remaining=" + if (expectingEOF) this.readBytes().toUHexString() else "[Not expecting EOF]" ", remaining=" + if (expectingEOF) this.readBytes().toUHexString() else "[Not expecting EOF]"
} }
try { try {