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.BigDecimaltoBigDecimal(byte[] bytes)Converts the given bytes to a BigDecimal.static booleantoBoolean(byte[] bytes)Converts the given bytes to boolean.static java.lang.BooleantoBooleanObject(byte[] bytes)Converts the given bytes to Boolean.static bytetoByte(byte[] bytes)Converts the given bytes to byte.static java.lang.BytetoByteObject(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 chartoChar(byte[] bytes)Converts the given bytes to char.static char[]toCharArray(byte[] bytes)Converts the given bytes to float.static java.lang.CharactertoCharObject(byte[] bytes)Converts the given bytes to Character.static java.util.CurrencytoCurrency(byte[] bytes)Converts the given bytes to Currency.static java.util.DatetoDate(byte[] bytes)Converts the given bytes to Date.static doubletoDouble(byte[] bytes)Converts the given bytes to double.static java.lang.DoubletoDoubleObject(byte[] bytes)Converts the given bytes to Double.static floattoFloat(byte[] bytes)Converts the given bytes to float.static java.lang.FloattoFloatObject(byte[] bytes)Converts the given bytes to Float.static inttoInt(byte[] bytes)Converts the given bytes to int.static java.lang.IntegertoIntObject(byte[] bytes)Converts the given bytes to Integer.static longtoLong(byte[] bytes)Converts the given bytes to long.static java.lang.LongtoLongObject(byte[] bytes)Converts the given bytes to Integer.static java.lang.ObjecttoObject(byte[] bytes)Converts a byte array to aSerializable.static RsDatetoRsDate(byte[] bytes)Converts the given bytes to Date.static RsDatetoRsDay(byte[] bytes)Converts the given bytes to Day.static RsMonthtoRsMonth(byte[] bytes)Converts the given bytes to Month.static RsYeartoRsYear(byte[] bytes)Converts the given bytes to Month.static shorttoShort(byte[] bytes)Converts the given bytes to short.static java.lang.ShorttoShortObject(byte[] bytes)Converts the given bytes to Short.static java.lang.StringtoString(byte[] bytes)Converts the given bytes to string (UTF8).static java.sql.TimestamptoTimestamp(byte[] bytes)Converts the given bytes to Date.static java.util.TimeZonetoTimeZone(byte[] bytes)Converts the given bytes to TimeZone.static java.net.URLtoURL(byte[] bytes)Converts the given bytes to URL.
-
Constructor Details
-
ConverterUtils
public ConverterUtils()
-
-
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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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
Converts the given parameter to its byte representation.- Parameters:
param- parameter- Returns:
- byte reresentation
-
toBytes
Converts the given parameter to its byte representation.- Parameters:
param- parameter- Returns:
- byte reresentation
-
toBytes
Converts the given parameter to its byte representation.- Parameters:
param- parameter- Returns:
- byte reresentation
-
toBytes
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.UnsupportedEncodingExceptionConverts 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
Converts the given bytes to Day.- Parameters:
bytes- bytes- Returns:
- Day value
-
toRsDate
Converts the given bytes to Date.- Parameters:
bytes- bytes- Returns:
- Date value
-
toRsMonth
Converts the given bytes to Month.- Parameters:
bytes- bytes- Returns:
- Month value
-
toRsYear
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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.UnsupportedEncodingExceptionConverts 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.MalformedURLExceptionConverts the given bytes to URL.- Parameters:
bytes- bytes- Returns:
- URL value
- Throws:
java.io.UnsupportedEncodingException- when character encoding is invalidjava.net.MalformedURLException- when URL is not valid
-
toBytes
public static byte[] toBytes(java.io.Serializable o) throws java.io.IOExceptionConverts 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.IOExceptionConverts a byte array to aSerializable.- Parameters:
bytes- the bytes from a serializable- Returns:
- the
Serializable - Throws:
java.lang.ClassNotFoundException- when class cannot be foundjava.io.IOException- when unserialization fails
-