private boolean needFirstLengthByteState(final boolean isBlocking,final boolean throwEofException) throws IOException {
  if (!isBlocking && in.available() <= 0) {
    return false;
  }
  int readByte=in.read();
  if (readByte == -1) {
    if (throwEofException) {
      final LocalizableMessage message=ERR_ASN1_TRUNCATED_LENGTH_BYTE.get();
      throw DecodeException.fatalError(message);
    }
    return false;
  }
  peekLength=readByte & 0x7F;
  if (peekLength != readByte) {
    lengthBytesNeeded=peekLength;
    if (lengthBytesNeeded > 4) {
      final LocalizableMessage message=ERR_ASN1_INVALID_NUM_LENGTH_BYTES.get(lengthBytesNeeded);
      throw DecodeException.fatalError(message);
    }
    peekLength=0x00;
    if (!isBlocking && (in.available() < lengthBytesNeeded)) {
      state=ASN1.ELEMENT_READ_STATE_NEED_ADDITIONAL_LENGTH_BYTES;
      return false;
    }
    while (lengthBytesNeeded > 0) {
      readByte=in.read();
      if (readByte == -1) {
        state=ASN1.ELEMENT_READ_STATE_NEED_ADDITIONAL_LENGTH_BYTES;
        if (throwEofException) {
          final LocalizableMessage message=ERR_ASN1_TRUNCATED_LENGTH_BYTES.get(lengthBytesNeeded);
          throw DecodeException.fatalError(message);
        }
        return false;
      }
      peekLength=(peekLength << 8) | (readByte & 0xFF);
      lengthBytesNeeded--;
    }
  }
  if (maxElementSize > 0 && peekLength > maxElementSize) {
    final LocalizableMessage message=ERR_LDAP_CLIENT_DECODE_MAX_REQUEST_SIZE_EXCEEDED.get(peekLength,maxElementSize);
    throw DecodeException.fatalError(message);
  }
  state=ASN1.ELEMENT_READ_STATE_NEED_VALUE_BYTES;
  return true;
}

private boolean needFirstLengthByteState ( final boolean isBlocking , final boolean throwEofException ) throws IOException { if ( ! isBlocking && in . available ( ) <= 0 ) { return false ; } int readByte = in . read ( ) ; if ( readByte == - 1 ) { if ( throwEofException ) { final LocalizableMessage message = ERR_ASN1_TRUNCATED_LENGTH_BYTE . get ( ) ; throw DecodeException . fatalError ( message ) ; } return false ; } peekLength = readByte & 0x7F ; if ( peekLength != readByte ) { lengthBytesNeeded = peekLength ; if ( lengthBytesNeeded > 4 ) { final LocalizableMessage message = ERR_ASN1_INVALID_NUM_LENGTH_BYTES . get ( lengthBytesNeeded ) ; throw DecodeException . fatalError ( message ) ; } peekLength = 0x00 ; if ( ! isBlocking && ( in . available ( ) < lengthBytesNeeded ) ) { state = ASN1 . ELEMENT_READ_STATE_NEED_ADDITIONAL_LENGTH_BYTES ; return false ; } while ( lengthBytesNeeded > 0 ) { readByte = in . read ( ) ; if ( readByte == - 1 ) { state = ASN1 . ELEMENT_READ_STATE_NEED_ADDITIONAL_LENGTH_BYTES ; if ( throwEofException ) { final LocalizableMessage message = ERR_ASN1_TRUNCATED_LENGTH_BYTES . get ( lengthBytesNeeded ) ; throw DecodeException . fatalError ( message ) ; } return false ; } peekLength = ( peekLength << 8 ) | ( readByte & 0xFF ) ; lengthBytesNeeded -- ; } } if ( maxElementSize > 0 && peekLength > maxElementSize ) { final LocalizableMessage message = ERR_LDAP_CLIENT_DECODE_MAX_REQUEST_SIZE_EXCEEDED . get ( peekLength , maxElementSize ) ; throw DecodeException . fatalError ( message ) ; } state = ASN1 . ELEMENT_READ_STATE_NEED_VALUE_BYTES ; return true ; }
internal helper method reading the first length bytes and transition to the next state if successful .
