public final class Convert extends Object
Modifier and Type | Method and Description |
---|---|
static String |
bytesToHex(byte[] bytes)
Converts a byte array to a Hexadecimal string representation.
|
static char[] |
charsToArray(CharSequence chars)
Converts a character sequence to a character array or
null . |
static byte[] |
charsToBytes(char[] chars)
Converts a character sequence to an UTF-8 byte array or
null . |
static byte[] |
compressBytes(byte[] bytes)
Compress the supplied bytes using the ZLIB algorithm.
|
static String |
compressedBytesToStr(byte[] bytes)
Uncompress supplied compressed UTF-8 bytes into a string.
|
static XMLGregorianCalendar |
dateToXcal(Date date)
Converts a
Date to an XMLGregorianCalendar . |
static XMLGregorianCalendar |
dateToXcal(LocalDateTime date)
Converts a
LocalDateTime to an XMLGregorianCalendar . |
static XMLGregorianCalendar |
gcalToXcal(GregorianCalendar gcal)
Converts a
GregorianCalendar to an XMLGregorianCalendar . |
static byte[] |
hexToBytes(String str)
Returns the byte array represented by supplied hexadecimal string.
|
static int |
hexToNibble(char hex)
Returns the nibble (4-bits) of the supplied hexadecimal char.
|
static String |
leftFill(char chr,
String text,
int size)
Returns the supplied text filled to its left to complete size.
|
static LocalDateTime |
msecToLocalDateTime(long msec)
Converts UTC milliseconds to a
LocalDateTime . |
static XMLGregorianCalendar |
msecToXcal(long msec)
Converts UTC milliseconds to an
XMLGregorianCalendar . |
static <T> T |
objectFromBytes(byte[] bytes,
Class<T> type)
Converts the supplied byte array to an object of specified type.
|
static byte[] |
objectToBytes(Serializable object)
Returns a byte array with the serialization of the supplied object.
|
static String |
rightFill(String text,
char chr,
int size)
Returns the supplied text filled to its right to complete size.
|
static byte[] |
serializeObject(Object object)
Serialize the supplied object instance to a byte array.
|
static char[] |
strToChars(String str)
Converts a string to a character array or
null . |
static byte[] |
strToCompressedBytes(String str)
Compress the UTF-8 bytes of the supplied string.
|
static byte[] |
uncompressBytes(byte[] bytes)
Uncompress the supplied bytes using the ZLIB algorithm.
|
static Object |
unserializeObject(byte[] bytes)
Unserialize the supplied byte array to an object instance.
|
static Object |
unserializeObject(InputStream input)
Unserialize the supplied input stream to an object instance.
|
static Date |
xcalToDate(XMLGregorianCalendar xcal)
Converts a
XMLGregorianCalendar to a Date . |
static GregorianCalendar |
xcalToGcal(XMLGregorianCalendar xcal)
Converts an
XMLGregorianCalendar to a GregorianCalendar . |
static LocalDateTime |
xcalToLocalDateTime(XMLGregorianCalendar xcal)
Converts an
XMLGregorianCalendar to a LocalDateTime . |
static long |
xcalToMsec(XMLGregorianCalendar xcal)
Converts an
XMLGregorianCalendar to UTC milliseconds. |
public static char[] strToChars(String str)
null
.str
- the string to be converted to a character array.null
if str
is null
.public static String leftFill(char chr, String text, int size)
chr
- the character used to left-fill the text
.text
- the string text to be left-filled with chr
.size
- the minimum length of the resulting string.NullPointerException
- if text
is null
.IllegalArgumentException
- if size
is negative.public static byte[] charsToBytes(char[] chars)
null
.chars
- the character sequence to convert to UTF-8 byte array.null
if chars
is null
.public static char[] charsToArray(CharSequence chars)
null
.chars
- the character sequence to convert to character array.null
if chars
is null
.public static String rightFill(String text, char chr, int size)
text
- the string text to be right-filled with chr
.chr
- the character used to right-fill the text
.size
- the minimum length of the resulting string.NullPointerException
- if text
is null
.IllegalArgumentException
- if size
is negative.public static String bytesToHex(byte[] bytes)
bytes
- the bytes to convert to a Hexadecimal representation.NullPointerException
- if bytes
is null
.public static byte[] hexToBytes(String str)
str
- the hexadecimal string to be converted.NullPointerException
- if str
is null
.IllegalArgumentException
- if str
is invalid.public static int hexToNibble(char hex)
hex
- the hexadecimal character.hex
char.IllegalArgumentException
- if hex
is invalid.public static XMLGregorianCalendar gcalToXcal(GregorianCalendar gcal)
GregorianCalendar
to an XMLGregorianCalendar
.gcal
- the Gregorian Calendar to be converted.XMLGregorianCalendar
created from gcal
.NullPointerException
- if gcal
is null
.public static XMLGregorianCalendar dateToXcal(Date date)
Date
to an XMLGregorianCalendar
.date
- the date instance to be converted.XMLGregorianCalendar
created from date
.NullPointerException
- if date
is null
.public static XMLGregorianCalendar dateToXcal(LocalDateTime date)
LocalDateTime
to an XMLGregorianCalendar
.date
- the local date time instance to be converted.XMLGregorianCalendar
created from date
.NullPointerException
- if date
is null
.public static XMLGregorianCalendar msecToXcal(long msec)
XMLGregorianCalendar
.msec
- the UTC milliseconds from the Epoch.XMLGregorianCalendar
created from msec
.public static LocalDateTime msecToLocalDateTime(long msec)
LocalDateTime
.msec
- the UTC milliseconds from the Epoch.LocalDateTime
created from msec
.public static GregorianCalendar xcalToGcal(XMLGregorianCalendar xcal)
XMLGregorianCalendar
to a GregorianCalendar
.xcal
- the XML Schema Date/Time to be converted.GregorianCalendar
created from xcal
.NullPointerException
- if xcal
is null
.public static Date xcalToDate(XMLGregorianCalendar xcal)
XMLGregorianCalendar
to a Date
.xcal
- the XML Schema Date/Time to be converted.Date
created from xcal
.NullPointerException
- if xcal
is null
.public static LocalDateTime xcalToLocalDateTime(XMLGregorianCalendar xcal)
XMLGregorianCalendar
to a LocalDateTime
.xcal
- the XML Schema Date/Time to be converted.LocalDateTime
created from xcal
.NullPointerException
- if xcal
is null
.public static long xcalToMsec(XMLGregorianCalendar xcal)
XMLGregorianCalendar
to UTC milliseconds.xcal
- the XML Schema Date/Time to be converted.xcal
.NullPointerException
- if xcal
is null
.public static byte[] strToCompressedBytes(String str) throws IOException
str
- the string to be compressed (can be null).null
if str
is null
.IOException
- if an I/O error occurs.public static String compressedBytesToStr(byte[] bytes) throws IOException
bytes
- the compressed UTF-8 bytes (can be null).null
if bytes
is null
.IOException
- if an I/O error occurs.public static byte[] compressBytes(byte[] bytes) throws IOException
bytes
- the bytes to compress with ZLIB algorithm (can be null).null
if bytes
is null
.IOException
- if an I/O error occurs.public static byte[] uncompressBytes(byte[] bytes) throws IOException
bytes
- the bytes to uncompress with ZLIB algorithm (can be null).null
if bytes
is null
.IOException
- if an I/O error occurs.public static byte[] serializeObject(Object object) throws IOException
object
- the object to be serialized into a byte array.null
if object
is null
.IOException
- if an I/O error occurs.public static Object unserializeObject(byte[] bytes) throws IOException, ClassNotFoundException
bytes
- the byte array to be unserialized into an object.null
if bytes
is null
.ClassNotFoundException
- the class of the object was not found.IOException
- if an I/O error occurs.public static Object unserializeObject(InputStream input) throws IOException, ClassNotFoundException
input
- the input stream containing the bytes to unserialize.NullPointerException
- if input
is null
.ClassNotFoundException
- the class of the object was not found.IOException
- if an I/O error occurs.public static byte[] objectToBytes(Serializable object) throws Exception
object
- the object instance to be converted to bytes.object
.NullPointerException
- if object
is null
.Exception
- if an error occurs converting to byte array.public static <T> T objectFromBytes(byte[] bytes, Class<T> type) throws Exception
T
- the type of the returned object.bytes
- the byte array to be unserialized.type
- the class type of the returned object.type
.NullPointerException
- if an argument is null
.Exception
- if an error occurs converting bytes to object.Copyright © OBCOM INGENIERIA S.A. (Chile). All Rights Reserved.