Class CmsDataTypeUtil

java.lang.Object
org.opencms.util.CmsDataTypeUtil

public final class CmsDataTypeUtil extends Object
Utilities to handle basic data types.

Since:
6.5.6
  • Method Details

    • dataDeserialize

      public static Object dataDeserialize(byte[] data, String type) throws IOException, ClassNotFoundException
      Returns the deserialized (if needed) object.

      Parameters:
      data - the data to deserialize
      type - the data type
      Returns:
      the deserialized object
      Throws:
      IOException - if the inputstream fails
      ClassNotFoundException - if the serialized object fails
    • dataExport

      public static String dataExport(Object data) throws IOException
      Returns a ready to export string representation of the given object.

      For not parseable objects, base64 encoded string with the serialized object is generated.

      Parameters:
      data - the object to export
      Returns:
      the string representation
      Throws:
      IOException - if something goes wrong
    • dataImport

      public static Object dataImport(String value, String type) throws ClassNotFoundException, IOException
      Returns the import data object.

      Parameters:
      value - the exported value
      type - the expected data type
      Returns:
      the import data object
      Throws:
      ClassNotFoundException - if something goes wrong
      IOException - if something goes wrong
    • dataSerialize

      public static byte[] dataSerialize(Object data) throws IOException
      Serialize the given data.

      Parameters:
      data - the data to serialize
      Returns:
      byte[] the serailized data
      Throws:
      IOException - if something goes wrong
    • format

      public static String format(boolean data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(byte data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(char data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(Date data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(double data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(float data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(int data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(long data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(Object data)
      Formats the given data into a string value depending on the data type.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • format

      public static String format(short data)
      Formats the given data into a string value.

      Parameters:
      data - the data to format
      Returns:
      a string representation of the given data
    • isParseable

      public static boolean isParseable(Class<?> clazz)
      Checks if the given class is representable as a string.

      Parameters:
      clazz - the type to test
      Returns:
      if the given class is representable as a string
    • numberToInt

      public static int numberToInt(Number n)
      Converts Number to int.

      Parameters:
      n - the number object
      Returns:
      Number.inValue(), 0 - if the parameter is null
    • parse

      public static Object parse(String data, Class<?> clazz)
      Returns an object of the given type (or a wrapper for base types) with the value of the given data.

      Parameters:
      data - the data to parse
      clazz - the data type
      Returns:
      the value of the given data
    • parseBoolean

      public static Boolean parseBoolean(String data)
      Parses the given data as a boolean.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseByte

      public static Byte parseByte(String data)
      Parses the given data as a byte.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseChar

      public static Character parseChar(String data)
      Parses the given data as a char.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseDate

      public static Date parseDate(String data)
      Parses the given data as a date.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseDouble

      public static Double parseDouble(String data)
      Parses the given data as a double.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseFloat

      public static Float parseFloat(String data)
      Parses the given data as a float.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseInt

      public static Integer parseInt(String data)
      Parses the given data as an integer.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseLong

      public static Long parseLong(String data)
      Parses the given data as a long.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseShort

      public static Short parseShort(String data)
      Parses the given data as a short.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value
    • parseUUID

      public static CmsUUID parseUUID(String data)
      Parses the given data as an uuid.

      Parameters:
      data - the data to parse
      Returns:
      the converted data value