caravan-protobuf/src/main/java/com/ctrip/soa/caravan/protobuf/v2/customization/CustomProtobufParser.java
/**
   * Helper method that will try to load at least specified number bytes in
   * input buffer, possible moving existing data around if necessary
   */
Helper method that will try to load at least specified number bytes in
input buffer, possible moving existing data around if necessary
Helper method that will try to load at least specified number bytes in input buffer possible moving existing data around if necessary
protected final void _loadToHaveAtLeastCtrip(int minAvailable) throws IOException
  {
    if (_inputStream == null) {
      throw _constructError("Needed to read "+minAvailable+" bytes, reached end-of-input");
    }
    int ptr = _inputPtr;
    int amount = _inputEnd - ptr;
    if (ptr > 0) {
      _currInputProcessed += ptr;
      if (amount > 0) {
        System.arraycopy(_inputBuffer, ptr, _inputBuffer, 0, amount);
      }
      _currentEndOffset = _parsingContext.adjustEnd(ptr);
    }
    _inputPtr = 0;
    _inputEnd = amount;
    while (_inputEnd < minAvailable) {
      int count = _inputStream.read(_inputBuffer, _inputEnd, _inputBuffer.length - _inputEnd);
      if (count < 1) {
        _closeInput();
        if (count == 0) {
          throw new IOException("InputStream.read() returned 0 characters when trying to read "+amount+" bytes");
        }
        throw _constructError("Needed to read "+minAvailable+" bytes, missed "+minAvailable+" before end-of-input");
      }
      _inputEnd += count;
    }
  }
protected final void _loadToHaveAtLeastCtrip ( int minAvailable ) throws IOException { if ( _inputStream == null ) { throw _constructError ( "Needed to read " + minAvailable + " bytes, reached end-of-input" ) ; } int ptr = _inputPtr ; int amount = _inputEnd - ptr ; if ( ptr > 0 ) { _currInputProcessed += ptr ; if ( amount > 0 ) { System . arraycopy ( _inputBuffer , ptr , _inputBuffer , 0 , amount ) ; } _currentEndOffset = _parsingContext . adjustEnd ( ptr ) ; } _inputPtr = 0 ; _inputEnd = amount ; while ( _inputEnd < minAvailable ) { int count = _inputStream . read ( _inputBuffer , _inputEnd , _inputBuffer . length - _inputEnd ) ; if ( count < 1 ) { _closeInput ( ) ; if ( count == 0 ) { throw new IOException ( "InputStream.read() returned 0 characters when trying to read " + amount + " bytes" ) ; } throw _constructError ( "Needed to read " + minAvailable + " bytes, missed " + minAvailable + " before end-of-input" ) ; } _inputEnd += count ; } }
Helper method that will try to load at least specified number bytes in
 input buffer, possible moving existing data around if necessary
Helper method that will try to load at least specified number bytes in input buffer possible moving existing data around if necessary
// No input stream, no leading (either we are closed, or have non-stream input source) // Need to move remaining data in front? // End of input // Should never return 0, so let's fail