int read(byte[] buffer,int offset,int length) throws IOException {
  int readLength=0;
  while (length > 0) {
    while (_chunkLength <= 0) {
      if (_isLastChunk)       return readLength == 0 ? -1 : readLength;
      int code=read();
switch (code) {
case BC_BINARY_CHUNK:
        _isLastChunk=false;
      _chunkLength=(read() << 8) + read();
    break;
case BC_BINARY:
  _isLastChunk=true;
_chunkLength=(read() << 8) + read();
break;
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
case 0x27:
case 0x28:
case 0x29:
case 0x2a:
case 0x2b:
case 0x2c:
case 0x2d:
case 0x2e:
case 0x2f:
_isLastChunk=true;
_chunkLength=code - 0x20;
break;
case 0x34:
case 0x35:
case 0x36:
case 0x37:
_isLastChunk=true;
_chunkLength=(code - 0x34) * 256 + read();
break;
default :
throw expect("byte[]",code);
}
}
int sublen=_chunkLength;
if (length < sublen) sublen=length;
if (_length <= _offset && !readBuffer()) return -1;
if (_length - _offset < sublen) sublen=_length - _offset;
System.arraycopy(_buffer,_offset,buffer,offset,sublen);
_offset+=sublen;
offset+=sublen;
readLength+=sublen;
length-=sublen;
_chunkLength-=sublen;
}
return readLength;
}

int read ( byte [ ] buffer , int offset , int length ) throws IOException { int readLength = 0 ; while ( length > 0 ) { while ( _chunkLength <= 0 ) { if ( _isLastChunk ) return readLength == 0 ? - 1 : readLength ; int code = read ( ) ; switch ( code ) { case BC_BINARY_CHUNK : _isLastChunk = false ; _chunkLength = ( read ( ) << 8 ) + read ( ) ; break ; case BC_BINARY : _isLastChunk = true ; _chunkLength = ( read ( ) << 8 ) + read ( ) ; break ; case 0x20 : case 0x21 : case 0x22 : case 0x23 : case 0x24 : case 0x25 : case 0x26 : case 0x27 : case 0x28 : case 0x29 : case 0x2a : case 0x2b : case 0x2c : case 0x2d : case 0x2e : case 0x2f : _isLastChunk = true ; _chunkLength = code - 0x20 ; break ; case 0x34 : case 0x35 : case 0x36 : case 0x37 : _isLastChunk = true ; _chunkLength = ( code - 0x34 ) * 256 + read ( ) ; break ; default : throw expect ( "byte[]" , code ) ; } } int sublen = _chunkLength ; if ( length < sublen ) sublen = length ; if ( _length <= _offset && ! readBuffer ( ) ) return - 1 ; if ( _length - _offset < sublen ) sublen = _length - _offset ; System . arraycopy ( _buffer , _offset , buffer , offset , sublen ) ; _offset += sublen ; offset += sublen ; readLength += sublen ; length -= sublen ; _chunkLength -= sublen ; } return readLength ; }
reads bytes from the underlying stream .
