Encode pour affichage en html.
@param text message à encoder
@param encodeSpace booléen selon que les espaces sont encodés en nbsp (insécables)
@return String
480574
public static String htmlEncode(String text, boolean encodeSpace) {
		// ces encodages html sont incomplets mais suffisants pour le monitoring
		String result = text.replaceAll("[&]", "&amp;").replaceAll("[<]", "&lt;")
				.replaceAll("[>]", "&gt;").replaceAll("[\n]", "<br/>");
		if (encodeSpace) {
			result = result.replaceAll(" ", "&nbsp;");
		}
		return result;
	}
1194329
@Override
	public String encodeAsString() {
		if(message.size == 0) return "";

		return new String(Base64Coder.encode(message.array, message.size));
	}
881159
public static String encodeString(String string, Charset charset) {
        if (charset == null)
            charset = ENCODING;
        byte[] bytes = null;
        bytes = string.getBytes(charset);

        int len = bytes.length;
        byte[] encoded = new byte[bytes.length * 3];
        int n = 0;
        boolean noEncode = true;

        for (int i = 0; i < len; i++) {
            byte b = bytes[i];

            if (b == ' ') {
                noEncode = false;
                encoded[n++] = (byte) '+';
            } else if (b >= 'a' && b <= 'z' ||
                    b >= 'A' && b <= 'Z' ||
                    b >= '0' && b <= '9') {
                encoded[n++] = b;
            } else {
                noEncode = false;
                encoded[n++] = (byte) '%';
                byte nibble = (byte) ((b & 0xf0) >> 4);
                if (nibble >= 10)
                    encoded[n++] = (byte) ('A' + nibble - 10);
                else
                    encoded[n++] = (byte) ('0' + nibble);
                nibble = (byte) (b & 0xf);
                if (nibble >= 10)
                    encoded[n++] = (byte) ('A' + nibble - 10);
                else
                    encoded[n++] = (byte) ('0' + nibble);
            }
        }

        if (noEncode)
            return string;

        return new String(encoded, 0, n, charset);
    }
796467
private static String encode(final String txt) {
        try {
            return URLEncoder.encode(
                txt, Charset.defaultCharset().name()
            );
        } catch (final UnsupportedEncodingException ex) {
            throw new IllegalStateException(ex);
        }
    }
291175
def html_encode(text):
    
    text = text.replace('&', '&amp;')
    text = text.replace('<', '&lt;')
    text = text.replace('>', '&gt;')
    text = text.replace('"', '&quot;')
    return text
1015854
private static String encode(String text, char[][] array) {
		int len;
		if ((text == null) || ((len = text.length()) == 0)) {
			return StrUtil.EMPTY;
		}
		StringBuilder buffer = new StringBuilder(len + (len >> 2));
		char c;
		for (int i = 0; i < len; i++) {
			c = text.charAt(i);
			if (c < 64) {
				buffer.append(array[c]);
			} else {
				buffer.append(c);
			}
		}
		return buffer.toString();
	}
885515
def encodeBase64(text, encoding='utf-8'):
    
    text = projex.text.toBytes(text, encoding)
    return base64.b64encode(text)
1357057
public Bits encodePPM(String text, int context) {
    final String original = text;
    //if(verbose) System.p.println(String.format("Encoding %s run %s chars of context", text, context));
    if (!text.endsWith("\u0000")) text += END_OF_STRING;
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    BitOutputStream out = new BitOutputStream(buffer);
    String contextStr = "";
    try {
      while (!text.isEmpty()) {
        String right = getRight(contextStr, context);
        TrieNode fromNode = inner.matchPredictor(right); // inner.matchEnd(right).getString()
        String prefix = fromNode.getString();
        // fromNode.getChildrenMap()
        TrieNode toNode = fromNode.traverse(text);
        int segmentChars = toNode.getDepth() - fromNode.getDepth();
        if (toNode.hasChildren()) {
          if (prefix.isEmpty() && 0 == segmentChars) {
            Optional<? extends TrieNode> child = toNode.getChild(ESCAPE);
            assert child.isPresent();
            toNode = child.get();
          }
          else {
            toNode = toNode.getChild(FALLBACK).get();
          }
        }
        
        Interval interval = fromNode.intervalTo(toNode);
        Bits segmentData = interval.toBits();
        if (verbose) {
          System.out.println(String.format(
            "Using context \"%s\", encoded \"%s\" (%s chars) as %s -> %s",
            fromNode.getDebugString(), toNode.getDebugString(fromNode), segmentChars, interval, segmentData));
        }
        out.write(segmentData);
        
        if (0 == segmentChars) {
          if (prefix.isEmpty()) {
            //throw new RuntimeException(String.format("Cannot encode %s in model", text.substring(0,1)));
            char exotic = text.charAt(0);
            out.write(exotic);
            if (verbose) {
              System.out.println(String.format(
                "Writing exotic character %s -> %s", exotic, new Bits(exotic, 16)));
            }
            text = text.substring(1);
          }
          else if (toNode.getChar() == FALLBACK) {
            contextStr = prefix.substring(1);
          }
          else {
            throw new RuntimeException("Cannot encode " + text.substring(0, 1));
          }
        }
        else {
          contextStr += text.substring(0, segmentChars);
          text = text.substring(segmentChars);
        }
      }
      out.flush();
      Bits bits = new Bits(buffer.toByteArray(), out.getTotalBitsWritten());
      //if(verbose) System.p.println(String.format("Encoded %s to %s", original, bits));
      return bits;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
1253576
@NotNull
    public static String encode(@NotNull byte[] source) {
        return encode(source, 0, source.length, ALPHABET, true);
    }
1183414
function __encode_utf8(text) {

        // Fill buffer with UTF-8
        for (var i=0; i<text.length; i++) {
            var codepoint = text.charCodeAt(i);
            __append_utf8(codepoint);
        }

        // Flush buffer
        if (length > 0) {
            var out_buffer = buffer.subarray(0, length);
            length = 0;
            return out_buffer;
        }

    }
185177
protected static byte[] encodeString(String string) {
        Element element = getStringCache().get(string);
        byte[] encoded = (element == null ? null : (byte[]) element.getObjectValue());
        if (encoded == null) {
            ByteBuffer buf = AMF.CHARSET.encode(string);
            encoded = new byte[buf.limit()];
            buf.get(encoded);
            getStringCache().put(new Element(string, encoded));
        }
        return encoded;
    }
1303996
def encode_text(text, fonts)
      # text must be a unicode string and fonts must be an array.
      # this is an internal method, don't perform tests.
      fonts_array = []
      fonts.each do |name|
        f = Fonts.get_font name
        fonts_array << f if f
      end

      # before starting, we should reorder any RTL content in the string
      text = reorder_rtl_content text

      out = []
      text.chars.each do |c|
        fonts_array.each_index do |i|
          next unless fonts_array[i].cmap.nil? || (fonts_array[i].cmap && fonts_array[i].cmap[c])
          # add to array
          if out.last.nil? || out.last[0] != fonts[i]
            out.last[1] << '>' unless out.last.nil?
            out << [fonts[i], '<', 0, 0]
          end
          out.last[1] << (fonts_array[i].cmap.nil? ? (c.unpack('H*')[0]) : fonts_array[i].cmap[c])
          if fonts_array[i].metrics[c]
            out.last[2] += fonts_array[i].metrics[c][:wx].to_f
            out.last[3] += fonts_array[i].metrics[c][:wy].to_f
          end
          break
        end
      end
      out.last[1] << '>' if out.last
      out
    end
441773
public static function encode($text, $charset = 'UTF-8')
    {
        $charset = Horde_String::lower($charset);
        $text = Horde_String::convertCharset($text, 'UTF-8', $charset);

        $encoded = $is_encoded = false;
        $lwsp = $word = null;
        $out = '';

        /* 0 = word unencoded
         * 1 = word encoded
         * 2 = spaces */
        $parts = array();

        /* Tokenize string. */
        for ($i = 0, $len = strlen($text); $i < $len; ++$i) {
            switch ($text[$i]) {
            case "\t":
            case "\r":
            case "\n":
                if (!is_null($word)) {
                    $parts[] = array(intval($encoded), $word, $i - $word);
                    $word = null;
                } elseif (!is_null($lwsp)) {
                    $parts[] = array(2, $lwsp, $i - $lwsp);
                    $lwsp = null;
                }

                $parts[] = array(0, $i, 1);
                break;

            case ' ':
                if (!is_null($word)) {
                    $parts[] = array(intval($encoded), $word, $i - $word);
                    $word = null;
                }
                if (is_null($lwsp)) {
                    $lwsp = $i;
                }
                break;

            default:
                if (is_null($word)) {
                    $encoded = false;
                    $word = $i;
                    if (!is_null($lwsp)) {
                        $parts[] = array(2, $lwsp, $i - $lwsp);
                        $lwsp = null;
                    }

                    /* Check for MIME encoding delimiter. Encode it if
                     * found. */
                    if (($text[$i] === '=') &&
                        (($i + 1) < $len) &&
                        ($text[$i +1] === '?')) {
                        ++$i;
                        $encoded = $is_encoded = true;
                    }
                }

                /* Check for 8-bit characters or control characters. */
                if (!$encoded) {
                    $c = ord($text[$i]);
                    if ($encoded = (($c & 0x80) || ($c < 32))) {
                        $is_encoded = true;
                    }
                }
                break;
            }
        }

        if (!$is_encoded) {
            return $text;
        }

        if (is_null($lwsp)) {
            $parts[] = array(intval($encoded), $word, $len);
        } else {
            $parts[] = array(2, $lwsp, $len);
        }

        /* Combine parts into MIME encoded string. */
        for ($i = 0, $cnt = count($parts); $i < $cnt; ++$i) {
            $val = $parts[$i];

            switch ($val[0]) {
            case 0:
            case 2:
                $out .= substr($text, $val[1], $val[2]);
                break;

            case 1:
                $j = $i;
                for ($k = $i + 1; $k < $cnt; ++$k) {
                    switch ($parts[$k][0]) {
                    case 0:
                        break 2;

                    case 1:
                        $i = $k;
                        break;
                    }
                }

                $encode = '';
                for (; $j <= $i; ++$j) {
                    $encode .= substr($text, $parts[$j][1], $parts[$j][2]);
                }

                $delim = '=?' . $charset . '?b?';
                $e_parts = explode(
                    self::EOL,
                    rtrim(
                        chunk_split(
                            base64_encode($encode),
                            /* strlen($delim) + 2 = space taken by MIME
                             * delimiter */
                            intval((75 - strlen($delim) + 2) / 4) * 4
                        )
                    )
                );

                $tmp = array();
                foreach ($e_parts as $val) {
                    $tmp[] = $delim . $val . '?=';
                }

                $out .= implode(' ', $tmp);
                break;
            }
        }

        return rtrim($out);
    }
561811
public static function encode($encodingLabel, $text)
    {
        $encodingLabel = self::normalizeEncoding($encodingLabel);
        if ($encodingLabel == 'ISO-8859-1')
            return self::toWin1252($text);
        return self::toUTF8($text);
    }
202246
private void encodeBytesBody(StringBuffer result, JsJmsBytesMessage msg) {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "encodeBytesBody");
    byte[] body = msg.getBytes();
    if (body != null) {
      result.append('~');
      HexString.binToHex(body, 0, body.length, result);
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "encodeBytesBody");
  }
380254
public static ByteBuffer encode(String text, Charset charset) {
		return encode(text.getBytes(charset));
	}
621836
public String encodeForWebClient() throws MessageEncodeFailedException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "encodeForWebClient");
    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "Encoding Web Message", ((MessageImpl)jmsMsg).debugMsg());

    // Make sure any transients necessary are written back to the message
    ((JsJmsMessageImpl)jmsMsg).updateDataFields(MfpConstants.UDF_ENCODE);

    StringBuffer result = new StringBuffer();

    // Version number
    result.append(1);

    // Message Id
    result.append('~');
    byte[] id = jmsMsg.getCorrelationIdAsBytes();
    if (id != null)
      HexString.binToHex(id, 0, id.length, result);

    // Message type
    result.append('~');
    String type = jmsMsg.getJmsxAppId();
    if (type == null || type.equals(MfpConstants.WPM_JMSXAPPID_VALUE))
      type = "SIB";
    URLEncode(result, type);

    // Message format
    result.append('~');
    result.append(jmsMsg.getFormat());

    // Topic
    result.append('~');
    String topic = jmsMsg.getDiscriminator();
    if (topic != null)
      URLEncode(result, topic);

    // Properties
    result.append('~');
    Set<String> names = jmsMsg.getPropertyNameSet();
    boolean first = true;
    for (Iterator<String> i = names.iterator(); i.hasNext(); ) {
      String name = i.next();

      // JMSXAppID is stored in the header field instead so ignore it here
      if (!name.equals(SIProperties.JMSXAppID)) {

        // All objects
        Object value = jmsMsg.getObjectProperty(name);
        if (value != null) {
          encodePair(result, name, value, first);
          first = false;
        }
      }
    }

    // Body
    if (jmsMsg instanceof JsJmsTextMessage)
      encodeTextBody(result, (JsJmsTextMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsBytesMessage)
      encodeBytesBody(result, (JsJmsBytesMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsObjectMessage)
      encodeObjectBody(result, (JsJmsObjectMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsStreamMessage)
      encodeStreamBody(result, (JsJmsStreamMessage)jmsMsg);
    else if (jmsMsg instanceof JsJmsMapMessage)
      encodeMapBody(result, (JsJmsMapMessage)jmsMsg);

    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(tc, "Encoded as web data", result);
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "encodeForWebClient");
    return result.toString();
  }