public int replaceEntity(char[] buffer,int start,int length) throws XMLStreamException {
  if (buffer[start + 1] == '#') {
    char c=buffer[start + 2];
    int base=(c == 'x') ? 16 : 10;
    int i=(c == 'x') ? 3 : 2;
    int charValue=0;
    for (; i < length - 1; i++) {
      c=buffer[start + i];
      charValue*=base;
      charValue+=(c <= '9') ? (c - '0') : (c <= 'Z') ? c - 'A' + 10 : c - 'a' + 10;
    }
    buffer[start]=(char)charValue;
    return 1;
  }
  if ((buffer[start + 1] == 'l') && (buffer[start + 2] == 't') && (buffer[start + 3] == ';')) {
    buffer[start]='<';
    return 1;
  }
  if ((buffer[start + 1] == 'g') && (buffer[start + 2] == 't') && (buffer[start + 3] == ';')) {
    buffer[start]='>';
    return 1;
  }
  if ((buffer[start + 1] == 'a') && (buffer[start + 2] == 'p') && (buffer[start + 3] == 'o')&& (buffer[start + 4] == 's')&& (buffer[start + 5] == ';')) {
    buffer[start]='\'';
    return 1;
  }
  if ((buffer[start + 1] == 'q') && (buffer[start + 2] == 'u') && (buffer[start + 3] == 'o')&& (buffer[start + 4] == 't')&& (buffer[start + 5] == ';')) {
    buffer[start]='"';
    return 1;
  }
  if ((buffer[start + 1] == 'a') && (buffer[start + 2] == 'm') && (buffer[start + 3] == 'p')&& (buffer[start + 4] == ';')) {
    buffer[start]='&';
    return 1;
  }
  _tmp.setArray(buffer,start + 1,length - 2);
  CharSequence replacementText=(_entitiesMapping != null) ? _entitiesMapping.get(_tmp) : null;
  if (replacementText == null)   throw new XMLStreamException("Entity " + _tmp + " not recognized");
  int replacementTextLength=replacementText.length();
  for (int i=0; i < replacementTextLength; i++) {
    buffer[start + i]=replacementText.charAt(i);
  }
  return replacementTextLength;
}

public int replaceEntity ( char [ ] buffer , int start , int length ) throws XMLStreamException { if ( buffer [ start + 1 ] == '#' ) { char c = buffer [ start + 2 ] ; int base = ( c == 'x' ) ? 16 : 10 ; int i = ( c == 'x' ) ? 3 : 2 ; int charValue = 0 ; for ( ; i < length - 1 ; i ++ ) { c = buffer [ start + i ] ; charValue *= base ; charValue += ( c <= '9' ) ? ( c - '0' ) : ( c <= 'Z' ) ? c - 'A' + 10 : c - 'a' + 10 ; } buffer [ start ] = ( char ) charValue ; return 1 ; } if ( ( buffer [ start + 1 ] == 'l' ) && ( buffer [ start + 2 ] == 't' ) && ( buffer [ start + 3 ] == ';' ) ) { buffer [ start ] = '<' ; return 1 ; } if ( ( buffer [ start + 1 ] == 'g' ) && ( buffer [ start + 2 ] == 't' ) && ( buffer [ start + 3 ] == ';' ) ) { buffer [ start ] = '>' ; return 1 ; } if ( ( buffer [ start + 1 ] == 'a' ) && ( buffer [ start + 2 ] == 'p' ) && ( buffer [ start + 3 ] == 'o' ) && ( buffer [ start + 4 ] == 's' ) && ( buffer [ start + 5 ] == ';' ) ) { buffer [ start ] = '\'' ; return 1 ; } if ( ( buffer [ start + 1 ] == 'q' ) && ( buffer [ start + 2 ] == 'u' ) && ( buffer [ start + 3 ] == 'o' ) && ( buffer [ start + 4 ] == 't' ) && ( buffer [ start + 5 ] == ';' ) ) { buffer [ start ] = '"' ; return 1 ; } if ( ( buffer [ start + 1 ] == 'a' ) && ( buffer [ start + 2 ] == 'm' ) && ( buffer [ start + 3 ] == 'p' ) && ( buffer [ start + 4 ] == ';' ) ) { buffer [ start ] = '&' ; return 1 ; } _tmp . setArray ( buffer , start + 1 , length - 2 ) ; CharSequence replacementText = ( _entitiesMapping != null ) ? _entitiesMapping . get ( _tmp ) : null ; if ( replacementText == null ) throw new XMLStreamException ( "Entity " + _tmp + " not recognized" ) ; int replacementTextLength = replacementText . length ( ) ; for ( int i = 0 ; i < replacementTextLength ; i ++ ) { buffer [ start + i ] = replacementText . charAt ( i ) ; } return replacementTextLength ; }
replaces the entity at the specified position . the five predefined xml entities " & # 38 ; lt ; " , " & # 38 ; gt ; " , " & # 38 ; apos ; " , " & # 38 ; quot ; " , " & # 38 ; amp ; " as well as character refererences ( decimal or hexadecimal ) are always recognized .
