docs: @SuppressWarnings("checkstyle:BooleanExpressionComplexity")
      public static String encodeID(final String aID) {
          Objects.requireNonNull(aID, LOGGER.getMessage(MessageCodes.PT_004));
  
          final byte[] bytes;
  
          try {
              bytes = aID.getBytes("utf-8");
          } catch (final UnsupportedEncodingException details) {
              throw new PairtreeRuntimeException(MessageCodes.PT_008, details);
          }
  
          final StringBuffer idBuffer = new StringBuffer();
  
          for (final byte b : bytes) {
              final int i = b & 0xff;
  
              if (i < 0x21 || i > 0x7e || i == 0x22 || i == 0x2a || i == 0x2b || i == 0x2c || i == 0x3c ||
                      i == 0x3d || i == 0x3e || i == 0x3f || i == 0x5c || i == 0x5e || i == 0x7c) {
                  // Encode
                  idBuffer.append(HEX_INDICATOR);
                  idBuffer.append(Integer.toHexString(i));
              } else {
                  // Don't encode
                  final char[] chars = Character.toChars(i);
  
                  assert chars.length == 1;
                  idBuffer.append(chars[0]);
              }
          }
  
          for (int index = 0; index < idBuffer.length(); index++) {
              final char character = idBuffer.charAt(index);
  
              // Encode characters that need to be encoded according to Pairtree specification
              if (character == PATH_SEP) {
                  idBuffer.setCharAt(index, EQUALS_SIGN);
              } else if (character == COLON) {
                  idBuffer.setCharAt(index, PLUS_SIGN);
              } else if (character == PERIOD) {
                  idBuffer.setCharAt(index, COMMA);
              }
          }
  
          return idBuffer.toString();
      }