StringUtils (Apache Tomcat 8.5.57 API Documentation)

org.apache.tomcat.util.codec.binary

## Class StringUtils

- java.lang.Object
- - org.apache.tomcat.util.codec.binary.StringUtils

-     public class StringUtils
      extends Object

  Converts String to and from bytes using the encodings required by the Java specification. These encodings are specified in Standard charsets.

  This class is immutable and thread-safe.

  Since:
    1.4
  See Also:
    Standard charsets

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringUtils()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static byte[]` | `getBytesUtf8(String string)` Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.
    `static String` | `newStringUsAscii(byte[] bytes)` Constructs a new `String` by decoding the specified array of bytes using the US-ASCII charset.
    `static String` | `newStringUtf8(byte[] bytes)` Constructs a new `String` by decoding the specified array of bytes using the UTF-8 charset.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StringUtils

          public StringUtils()

  - ### Method Detail

    - #### getBytesUtf8

          public static byte[] getBytesUtf8(String string)

      Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.
      Parameters:
        `string` - the String to encode, may be `null`
      Returns:
        encoded bytes, or `null` if the input string was `null`
      See Also:
        Standard charsets

    - #### newStringUsAscii

          public static String newStringUsAscii(byte[] bytes)

      Constructs a new `String` by decoding the specified array of bytes using the US-ASCII charset.
      Parameters:
        `bytes` - The bytes to be decoded into characters
      Returns:
        A new `String` decoded from the specified array of bytes using the US-ASCII charset, or `null` if the input byte array was `null`.

    - #### newStringUtf8

          public static String newStringUtf8(byte[] bytes)

      Constructs a new `String` by decoding the specified array of bytes using the UTF-8 charset.
      Parameters:
        `bytes` - The bytes to be decoded into characters
      Returns:
        A new `String` decoded from the specified array of bytes using the UTF-8 charset, or `null` if the input byte array was `null`.

Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.