Class CmsDataTypeUtil


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

    Since:
    6.5.6
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object dataDeserialize​(byte[] data, java.lang.String type)
      Returns the deserialized (if needed) object.
      static java.lang.String dataExport​(java.lang.Object data)
      Returns a ready to export string representation of the given object.
      static java.lang.Object dataImport​(java.lang.String value, java.lang.String type)
      Returns the import data object.
      static byte[] dataSerialize​(java.lang.Object data)
      Serialize the given data.
      static java.lang.String format​(boolean data)
      Formats the given data into a string value.
      static java.lang.String format​(byte data)
      Formats the given data into a string value.
      static java.lang.String format​(char data)
      Formats the given data into a string value.
      static java.lang.String format​(double data)
      Formats the given data into a string value.
      static java.lang.String format​(float data)
      Formats the given data into a string value.
      static java.lang.String format​(int data)
      Formats the given data into a string value.
      static java.lang.String format​(long data)
      Formats the given data into a string value.
      static java.lang.String format​(short data)
      Formats the given data into a string value.
      static java.lang.String format​(java.lang.Object data)
      Formats the given data into a string value depending on the data type.
      static java.lang.String format​(java.util.Date data)
      Formats the given data into a string value.
      static boolean isParseable​(java.lang.Class<?> clazz)
      Checks if the given class is representable as a string.
      static int numberToInt​(java.lang.Number n)
      Converts Number to int.
      static java.lang.Object parse​(java.lang.String data, java.lang.Class<?> clazz)
      Returns an object of the given type (or a wrapper for base types) with the value of the given data.
      static java.lang.Boolean parseBoolean​(java.lang.String data)
      Parses the given data as a boolean.
      static java.lang.Byte parseByte​(java.lang.String data)
      Parses the given data as a byte.
      static java.lang.Character parseChar​(java.lang.String data)
      Parses the given data as a char.
      static java.util.Date parseDate​(java.lang.String data)
      Parses the given data as a date.
      static java.lang.Double parseDouble​(java.lang.String data)
      Parses the given data as a double.
      static java.lang.Float parseFloat​(java.lang.String data)
      Parses the given data as a float.
      static java.lang.Integer parseInt​(java.lang.String data)
      Parses the given data as an integer.
      static java.lang.Long parseLong​(java.lang.String data)
      Parses the given data as a long.
      static java.lang.Short parseShort​(java.lang.String data)
      Parses the given data as a short.
      static CmsUUID parseUUID​(java.lang.String data)
      Parses the given data as an uuid.
      • Methods inherited from class java.lang.Object

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

      • dataDeserialize

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

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

        public static java.lang.String dataExport​(java.lang.Object data)
                                           throws java.io.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:
        java.io.IOException - if something goes wrong
      • dataImport

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

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

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

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

        public static java.lang.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 java.lang.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 java.lang.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 java.lang.String format​(java.util.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String format​(java.lang.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 java.lang.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​(java.lang.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​(java.lang.Number n)
        Converts Number to int.

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

        public static java.lang.Object parse​(java.lang.String data,
                                             java.lang.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 java.lang.Boolean parseBoolean​(java.lang.String data)
        Parses the given data as a boolean.

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

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

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

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

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

        public static java.util.Date parseDate​(java.lang.String data)
        Parses the given data as a date.

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

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

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

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

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

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

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

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

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

        public static java.lang.Short parseShort​(java.lang.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​(java.lang.String data)
        Parses the given data as an uuid.

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