Package rs.baselib.io

Class ConverterUtils

java.lang.Object
rs.baselib.io.ConverterUtils

public class ConverterUtils
extends java.lang.Object
Provides simple methods vor converting bytes into objects and back.
Author:
ralph
  • Constructor Summary

    Constructors 
    Constructor Description
    ConverterUtils()  
  • Method Summary

    Modifier and Type Method Description
    static java.math.BigDecimal toBigDecimal​(byte[] bytes)
    Converts the given bytes to a BigDecimal.
    static boolean toBoolean​(byte[] bytes)
    Converts the given bytes to boolean.
    static java.lang.Boolean toBooleanObject​(byte[] bytes)
    Converts the given bytes to Boolean.
    static byte toByte​(byte[] bytes)
    Converts the given bytes to byte.
    static java.lang.Byte toByteObject​(byte[] bytes)
    Converts the given bytes to Byte.
    static byte[] toBytes​(boolean param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(byte param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(char param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(char[] param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(double param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(float param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(int param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(long param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(short param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.io.Serializable o)
    Converts the given Serializable to its byte representation.
    static byte[] toBytes​(java.lang.Boolean param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.Byte param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.Character param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.Double param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.Float param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.Integer param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.Long param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.Short param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.lang.String param)
    Converts the given parameter (UTF8) to its byte representation.
    static byte[] toBytes​(java.math.BigDecimal param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.net.URL param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.sql.Timestamp param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.util.Currency param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.util.Date param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(java.util.TimeZone param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(RsDate param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(RsDay param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(RsMonth param)
    Converts the given parameter to its byte representation.
    static byte[] toBytes​(RsYear param)
    Converts the given parameter to its byte representation.
    static char toChar​(byte[] bytes)
    Converts the given bytes to char.
    static char[] toCharArray​(byte[] bytes)
    Converts the given bytes to float.
    static java.lang.Character toCharObject​(byte[] bytes)
    Converts the given bytes to Character.
    static java.util.Currency toCurrency​(byte[] bytes)
    Converts the given bytes to Currency.
    static java.util.Date toDate​(byte[] bytes)
    Converts the given bytes to Date.
    static double toDouble​(byte[] bytes)
    Converts the given bytes to double.
    static java.lang.Double toDoubleObject​(byte[] bytes)
    Converts the given bytes to Double.
    static float toFloat​(byte[] bytes)
    Converts the given bytes to float.
    static java.lang.Float toFloatObject​(byte[] bytes)
    Converts the given bytes to Float.
    static int toInt​(byte[] bytes)
    Converts the given bytes to int.
    static java.lang.Integer toIntObject​(byte[] bytes)
    Converts the given bytes to Integer.
    static long toLong​(byte[] bytes)
    Converts the given bytes to long.
    static java.lang.Long toLongObject​(byte[] bytes)
    Converts the given bytes to Integer.
    static java.lang.Object toObject​(byte[] bytes)
    Converts a byte array to a Serializable.
    static RsDate toRsDate​(byte[] bytes)
    Converts the given bytes to Date.
    static RsDate toRsDay​(byte[] bytes)
    Converts the given bytes to Day.
    static RsMonth toRsMonth​(byte[] bytes)
    Converts the given bytes to Month.
    static RsYear toRsYear​(byte[] bytes)
    Converts the given bytes to Month.
    static short toShort​(byte[] bytes)
    Converts the given bytes to short.
    static java.lang.Short toShortObject​(byte[] bytes)
    Converts the given bytes to Short.
    static java.lang.String toString​(byte[] bytes)
    Converts the given bytes to string (UTF8).
    static java.sql.Timestamp toTimestamp​(byte[] bytes)
    Converts the given bytes to Date.
    static java.util.TimeZone toTimeZone​(byte[] bytes)
    Converts the given bytes to TimeZone.
    static java.net.URL toURL​(byte[] bytes)
    Converts the given bytes to URL.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • toBytes

      public static byte[] toBytes​(short param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Short param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toShort

      public static short toShort​(byte[] bytes)
      Converts the given bytes to short.
      Parameters:
      bytes - bytes
      Returns:
      short value
    • toShortObject

      public static java.lang.Short toShortObject​(byte[] bytes)
      Converts the given bytes to Short.
      Parameters:
      bytes - bytes
      Returns:
      Short object
    • toBytes

      public static byte[] toBytes​(int param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Integer param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toInt

      public static int toInt​(byte[] bytes)
      Converts the given bytes to int.
      Parameters:
      bytes - bytes
      Returns:
      int value
    • toIntObject

      public static java.lang.Integer toIntObject​(byte[] bytes)
      Converts the given bytes to Integer.
      Parameters:
      bytes - bytes
      Returns:
      Integer object
    • toBytes

      public static byte[] toBytes​(long param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Long param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toLong

      public static long toLong​(byte[] bytes)
      Converts the given bytes to long.
      Parameters:
      bytes - bytes
      Returns:
      long value
    • toLongObject

      public static java.lang.Long toLongObject​(byte[] bytes)
      Converts the given bytes to Integer.
      Parameters:
      bytes - bytes
      Returns:
      Integer object
    • toBytes

      public static byte[] toBytes​(float param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Float param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toFloat

      public static float toFloat​(byte[] bytes)
      Converts the given bytes to float.
      Parameters:
      bytes - bytes
      Returns:
      float value
    • toFloatObject

      public static java.lang.Float toFloatObject​(byte[] bytes)
      Converts the given bytes to Float.
      Parameters:
      bytes - bytes
      Returns:
      Float object
    • toBytes

      public static byte[] toBytes​(double param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Double param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toDouble

      public static double toDouble​(byte[] bytes)
      Converts the given bytes to double.
      Parameters:
      bytes - bytes
      Returns:
      double value
    • toDoubleObject

      public static java.lang.Double toDoubleObject​(byte[] bytes)
      Converts the given bytes to Double.
      Parameters:
      bytes - bytes
      Returns:
      Double object
    • toBytes

      public static byte[] toBytes​(char param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Character param) throws java.io.UnsupportedEncodingException
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toChar

      public static char toChar​(byte[] bytes) throws java.io.UnsupportedEncodingException
      Converts the given bytes to char.
      Parameters:
      bytes - bytes
      Returns:
      char value
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toCharObject

      public static java.lang.Character toCharObject​(byte[] bytes) throws java.io.UnsupportedEncodingException
      Converts the given bytes to Character.
      Parameters:
      bytes - bytes
      Returns:
      Character object
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toBytes

      public static byte[] toBytes​(char[] param) throws java.io.UnsupportedEncodingException
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toCharArray

      public static char[] toCharArray​(byte[] bytes) throws java.io.UnsupportedEncodingException
      Converts the given bytes to float.
      Parameters:
      bytes - bytes
      Returns:
      float value
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toBytes

      public static byte[] toBytes​(byte param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Byte param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toByte

      public static byte toByte​(byte[] bytes)
      Converts the given bytes to byte.
      Parameters:
      bytes - bytes
      Returns:
      byte value
    • toByteObject

      public static java.lang.Byte toByteObject​(byte[] bytes)
      Converts the given bytes to Byte.
      Parameters:
      bytes - bytes
      Returns:
      Byte object
    • toBytes

      public static byte[] toBytes​(boolean param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.lang.Boolean param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBoolean

      public static boolean toBoolean​(byte[] bytes)
      Converts the given bytes to boolean.
      Parameters:
      bytes - bytes
      Returns:
      boolean value
    • toBooleanObject

      public static java.lang.Boolean toBooleanObject​(byte[] bytes)
      Converts the given bytes to Boolean.
      Parameters:
      bytes - bytes
      Returns:
      Boolean object
    • toBytes

      public static byte[] toBytes​(java.lang.String param) throws java.io.UnsupportedEncodingException
      Converts the given parameter (UTF8) to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toString

      public static java.lang.String toString​(byte[] bytes) throws java.io.UnsupportedEncodingException
      Converts the given bytes to string (UTF8).
      Parameters:
      bytes - bytes
      Returns:
      string value
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toBytes

      public static byte[] toBytes​(java.util.Date param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(java.math.BigDecimal param) throws java.io.UnsupportedEncodingException
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
      Since:
      1.3.2
    • toBytes

      public static byte[] toBytes​(RsDate param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(RsMonth param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(RsYear param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toBytes

      public static byte[] toBytes​(RsDay param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toDate

      public static java.util.Date toDate​(byte[] bytes)
      Converts the given bytes to Date.
      Parameters:
      bytes - bytes
      Returns:
      Date value
    • toBigDecimal

      public static java.math.BigDecimal toBigDecimal​(byte[] bytes) throws java.io.UnsupportedEncodingException
      Converts the given bytes to a BigDecimal.
      Parameters:
      bytes - bytes
      Returns:
      BigDecimal value
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
      Since:
      1.3.2
    • toRsDay

      public static RsDate toRsDay​(byte[] bytes)
      Converts the given bytes to Day.
      Parameters:
      bytes - bytes
      Returns:
      Day value
    • toRsDate

      public static RsDate toRsDate​(byte[] bytes)
      Converts the given bytes to Date.
      Parameters:
      bytes - bytes
      Returns:
      Date value
    • toRsMonth

      public static RsMonth toRsMonth​(byte[] bytes)
      Converts the given bytes to Month.
      Parameters:
      bytes - bytes
      Returns:
      Month value
    • toRsYear

      public static RsYear toRsYear​(byte[] bytes)
      Converts the given bytes to Month.
      Parameters:
      bytes - bytes
      Returns:
      Month value
    • toBytes

      public static byte[] toBytes​(java.sql.Timestamp param)
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
    • toTimestamp

      public static java.sql.Timestamp toTimestamp​(byte[] bytes)
      Converts the given bytes to Date.
      Parameters:
      bytes - bytes
      Returns:
      Timestamp value
    • toBytes

      public static byte[] toBytes​(java.util.Currency param) throws java.io.UnsupportedEncodingException
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toCurrency

      public static java.util.Currency toCurrency​(byte[] bytes) throws java.io.UnsupportedEncodingException
      Converts the given bytes to Currency.
      Parameters:
      bytes - bytes
      Returns:
      Currency value
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toBytes

      public static byte[] toBytes​(java.util.TimeZone param) throws java.io.UnsupportedEncodingException
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toTimeZone

      public static java.util.TimeZone toTimeZone​(byte[] bytes) throws java.io.UnsupportedEncodingException
      Converts the given bytes to TimeZone.
      Parameters:
      bytes - bytes
      Returns:
      TimeZone value
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toBytes

      public static byte[] toBytes​(java.net.URL param) throws java.io.UnsupportedEncodingException
      Converts the given parameter to its byte representation.
      Parameters:
      param - parameter
      Returns:
      byte reresentation
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
    • toURL

      public static java.net.URL toURL​(byte[] bytes) throws java.io.UnsupportedEncodingException, java.net.MalformedURLException
      Converts the given bytes to URL.
      Parameters:
      bytes - bytes
      Returns:
      URL value
      Throws:
      java.io.UnsupportedEncodingException - when character encoding is invalid
      java.net.MalformedURLException - when URL is not valid
    • toBytes

      public static byte[] toBytes​(java.io.Serializable o) throws java.io.IOException
      Converts the given Serializable to its byte representation.
      Parameters:
      o - serializable
      Returns:
      byte reresentation
      Throws:
      java.io.IOException - when serialization fails
    • toObject

      public static java.lang.Object toObject​(byte[] bytes) throws java.lang.ClassNotFoundException, java.io.IOException
      Converts a byte array to a Serializable.
      Parameters:
      bytes - the bytes from a serializable
      Returns:
      the Serializable
      Throws:
      java.lang.ClassNotFoundException - when class cannot be found
      java.io.IOException - when unserialization fails