code: private int outputHexCharref() {
          final byte[] utfBytes;
          final int utfP;
          int utfLen;
  
          if (caseInsensitiveEquals(lastError.source, "UTF-32BE".getBytes())) {
              utfBytes = lastError.errorBytes;
              utfP = lastError.errorBytesP;
              utfLen = lastError.errorBytesLength;
          } else {
              Ptr utfLenA = new Ptr();
  
              // TODO: better calculation?
              byte[] utfBuf = new byte[lastError.errorBytesLength * UTF32BEEncoding.INSTANCE.maxLength()];
              utfBytes = allocateConvertedString(lastError.source, "UTF-32BE".getBytes(), lastError.errorBytes, lastError.errorBytesP, lastError.errorBytesLength, utfBuf, utfLenA);
  
              if (utfBytes == null) return -1;
              utfP = 0;
              utfLen = utfLenA.p;
          }
  
          if (utfLen % 4 != 0) return -1;
  
          int p = utfP;
          while (4 <= utfLen) {
              int u = 0; // long ??
              u += (utfBytes[p] & 0xff) << 24;
              u += (utfBytes[p + 1] & 0xff) << 16;
              u += (utfBytes[p + 2] & 0xff) << 8;
              u += (utfBytes[p + 3] & 0xff);
              byte[] charrefbuf = String.format("&#x%X;", u).getBytes(); // FIXME: use faster sprintf ??
  
              if (insertOutput(charrefbuf, 0, charrefbuf.length, "US-ASCII".getBytes()) == -1) return -1;
  
              p += 4;
              utfLen -= 4;
          }
  
          return 0;
      }
docs: /* output_hex_charref