code: public static String decodeHtmlEntities(String input, String encoding) {
  
          Matcher matcher = ENTITIY_PATTERN.matcher(input);
          StringBuffer result = new StringBuffer(input.length());
          Charset charset = Charset.forName(encoding);
          CharsetEncoder encoder = charset.newEncoder();
  
          while (matcher.find()) {
              String entity = matcher.group();
              String value = entity.substring(2, entity.length() - 1);
              int c = Integer.valueOf(value).intValue();
              if (c < 128) {
                  // first 128 chars are contained in almost every charset
                  entity = new String(new char[] {(char)c});
                  // this is intended as performance improvement since
                  // the canEncode() operation appears quite CPU heavy
              } else if (encoder.canEncode((char)c)) {
                  // encoder can encode this char
                  entity = new String(new char[] {(char)c});
              }
              matcher.appendReplacement(result, entity);
          }
          matcher.appendTail(result);
          return result.toString();
      }
docs: Decodes HTML entity references like <code>&amp;#8364;</code> that are contained in the
  String to a regular character, but only if that character is contained in the given
  encodings charset.<p>
  
  @param input the input to decode the HTML entities in
  @param encoding the charset to decode the input for
  @return the input with the decoded HTML entities
  
  @see #encodeHtmlEntities(String, String)