HCOLL-211 Add BytesMarshaller and improve handling of invalid sizes.

This commit is contained in:
Peter Lawrey
2014-11-30 14:18:45 +02:00
parent 50a337af0d
commit 6fdfc9184c
2 changed files with 6 additions and 5 deletions
@@ -89,11 +89,13 @@ public class StringEncodingExamplesTest {
@Override
public CharSequence read(Bytes bytes) {
int csLen = (int) bytes.readStopBit();
long csLen = bytes.readStopBit();
if (csLen < 0 || csLen > Integer.MAX_VALUE)
throw new IllegalStateException("length invalid: " + csLen);
if (returnedCharBuffer == null || returnedCharBuffer.capacity() < csLen) {
returnedCharBuffer = CharBuffer.allocate(csLen);
returnedCharBuffer = CharBuffer.allocate((int) csLen);
} else {
returnedCharBuffer.clear().limit(csLen);
returnedCharBuffer.clear().limit((int) csLen);
}
bytesAsBuffer = bytes.sliceAsByteBuffer(bytesAsBuffer);
decoder.decode(bytesAsBuffer, returnedCharBuffer, true);