Class StringEncoder


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int encodeIsoChars​(java.lang.CharSequence charArray, int charIndex, byte[] byteArray, int byteIndex, int length)  
      static byte[] encodeSingleByteChars​(java.lang.CharSequence s)
      Encodes the specified char sequence by casting each character to a byte.
      static int encodeString​(java.lang.CharSequence charArray, int charOffset, int charLength, byte[] byteArray)  
      static byte[] toBytes​(java.lang.String str, java.nio.charset.Charset charset)
      Converts a String to a byte[].
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toBytes

        public static byte[] toBytes​(java.lang.String str,
                                     java.nio.charset.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​(java.lang.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​(java.lang.CharSequence charArray,
                                         int charIndex,
                                         byte[] byteArray,
                                         int byteIndex,
                                         int length)
      • encodeString

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