Class StringEncoder


  • public final class StringEncoder
    extends Object
    Encodes Strings to bytes.
    Since:
    2.5
    • Method Detail

      • toBytes

        public static byte[] toBytes​(String str,
                                     Charset charset)
        Converts a String to a byte[].
        Parameters:
        str - if null, return null.
        charset - if null, use the default charset.
        Returns:
        a byte[]
      • encodeSingleByteChars

        public static byte[] encodeSingleByteChars​(CharSequence s)
        Encodes the specified char sequence by casting each character to a byte.
        Parameters:
        s - the char sequence to encode
        Returns:
        the encoded String
        See Also:
        LOG4J2-1151
      • encodeIsoChars

        public static int encodeIsoChars​(CharSequence charArray,
                                         int charIndex,
                                         byte[] byteArray,
                                         int byteIndex,
                                         int length)
      • encodeString

        public static int encodeString​(CharSequence charArray,
                                       int charOffset,
                                       int charLength,
                                       byte[] byteArray)