java.lang.Object
org.camunda.bpm.engine.impl.digest._apacheCommonsCodec.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
Since:
1.4
Version:
$Id: StringUtils.java 801391 2009-08-05 19:55:54Z ggregory $
Author:
Gary Gregory
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    getBytesUnchecked(String string, String charsetName)
    Encodes the given string into a sequence of bytes using the named charset, storing the result into a new byte array.
    static byte[]
    Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.
    static String
    newString(byte[] bytes, String charsetName)
    Constructs a new String by decoding the specified array of bytes using the given 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
  • Field Details

  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • newString

      public static String newString(byte[] bytes, String charsetName)
      Constructs a new String by decoding the specified array of bytes using the given charset.

      This method catches UnsupportedEncodingException and re-throws it as IllegalStateException, which should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.

      Parameters:
      bytes - The bytes to be decoded into characters
      charsetName - The name of a required Charset
      Returns:
      A new String decoded from the specified array of bytes using the given charset.
      Throws:
      IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen for a required charset name.
      See Also:
    • 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 given charset.
      Throws:
      IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the charset is required.
    • 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
      Returns:
      encoded bytes
      Throws:
      IllegalStateException - Thrown when the charset is missing, which should be never according the the Java specification.
      See Also:
    • getBytesUnchecked

      public static byte[] getBytesUnchecked(String string, String charsetName)
      Encodes the given string into a sequence of bytes using the named charset, storing the result into a new byte array.

      This method catches UnsupportedEncodingException and rethrows it as IllegalStateException, which should never happen for a required charset name. Use this method when the encoding is required to be in the JRE.

      Parameters:
      string - the String to encode
      charsetName - The name of a required Charset
      Returns:
      encoded bytes
      Throws:
      IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen for a required charset name.
      See Also: