in src/main/java/com/alibaba/com/caucho/hessian/io/Hessian2Input.java [2010:2072]
public int readBytes(byte[] buffer, int offset, int length)
throws IOException {
int readLength = 0;
if (_chunkLength == END_OF_DATA) {
_chunkLength = 0;
return -1;
} else if (_chunkLength == 0) {
int tag = read();
switch (tag) {
case 'N':
return -1;
case 'B':
case BC_BINARY_CHUNK:
_isLastChunk = tag == 'B';
_chunkLength = (read() << 8) + read();
break;
default:
throw expect("binary", tag);
}
}
while (length > 0) {
if (_chunkLength > 0) {
buffer[offset++] = (byte) read();
_chunkLength--;
length--;
readLength++;
} else if (_isLastChunk) {
if (readLength == 0)
return -1;
else {
_chunkLength = END_OF_DATA;
return readLength;
}
} else {
int tag = read();
switch (tag) {
case 'B':
case BC_BINARY_CHUNK:
_isLastChunk = tag == 'B';
_chunkLength = (read() << 8) + read();
break;
default:
throw expect("binary", tag);
}
}
}
if (readLength == 0)
return -1;
else if (_chunkLength > 0 || !_isLastChunk)
return readLength;
else {
_chunkLength = END_OF_DATA;
return readLength;
}
}