Class StringUtils

java.lang.Object
com.restfb.util.StringUtils

public final class StringUtils
extends Object
A collection of string-handling utility methods.
Since:
1.6
Author:
Mark Allen
  • Field Details

  • Method Details

    • isBlank

      public static boolean isBlank​(String string)
      Is string blank (null or only whitespace)?
      Parameters:
      string - The string to check.
      Returns:
      true if string is blank, false otherwise.
    • trimToNull

      public static String trimToNull​(String string)
      Returns a trimmed version of string, or null if string is null or the trimmed version is a blank string.
      Parameters:
      string - The string to trim.
      Returns:
      A trimmed version of string, or null if string is null or the trimmed version is a blank string.
    • trimToEmpty

      public static String trimToEmpty​(String string)
      Returns a trimmed version of string, or an empty string if string is null or the trimmed version is a blank string.
      Parameters:
      string - The string to trim.
      Returns:
      A trimmed version of string, or an empty string if string is null or the trimmed version is a blank string.
    • toBytes

      public static byte[] toBytes​(String string)
      Converts string to a byte array.

      Assumes string is in ENCODING_CHARSET format.

      Parameters:
      string - The string to convert to a byte array.
      Returns:
      A byte array representation of string.
      Throws:
      NullPointerException - If string is null.
      IllegalStateException - If unable to convert because the JVM doesn't support ENCODING_CHARSET.
    • toString

      public static String toString​(byte[] data)
      Converts data to a string in ENCODING_CHARSET format.
      Parameters:
      data - The data to convert to a string.
      Returns:
      A string representation of data.
      Throws:
      NullPointerException - If data is null.
      IllegalStateException - If unable to convert because the JVM doesn't support ENCODING_CHARSET.
      Since:
      1.6.13
    • fromInputStream

      public static String fromInputStream​(InputStream inputStream) throws IOException
      Builds and returns a string representation of the given inputStream .
      Parameters:
      inputStream - The stream from which a string representation is built.
      Returns:
      A string representation of the given inputStream.
      Throws:
      IOException - If an error occurs while processing the inputStream.
    • toInteger

      public static Integer toInteger​(String string)
      Returns an Integer representation of the given string, or null if it's not a valid Integer.
      Parameters:
      string - The string to process.
      Returns:
      The Integer representation of string, or null if string is null or not a valid Integer.