Class Converter
java.lang.Object
clazzfish.monitor.util.Converter
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
classToResource
(String name) Converts a classname (e.g.static Serializable
deserialize
(byte[] bytes) Deserializes the given byte array and returns it as object.static String
getMemoryAsString
(long mem) Gets the memory as string.static String
getTimeAsString
(double timeInMillis) Gets the time as string with the corresponding unit.static String
getTimeAsString
(double timeInMillis, Locale locale) Gets the time as string with the corresponding unit.static String
getTimeAsString
(long timeInMillis) Gets the time as string with the corresponding unit.static String
packageToResource
(String name) Converts a package name (e.g.static String
resourceToClass
(String name) Converts a resource (e.g.static byte[]
serialize
(Serializable object) Serializes the given object and returns it as byte array.static String
toAbsolutePath
(URI uri) Converts an URI into a file and returns it as absolute pathname.static Object[]
Converts variable number of arguments into an object array.static Date
Converts a string to a date by trying different date patterns.static Date
Converts a string to a date with the help of the given pattern.static File
Converts an URI into a file.static File
Converts an URI into a file.static String
toLongString
(Object obj) Converts an object into a long representation as the normal toString method.static String
toLongString
(Object[] array) If you want to print each element of an array into a single line you can use this method here.static String
toLongString
(StackTraceElement[] stacktrace) This implementation prints the stacktrace in a similar way as the printStacktrace method ofThrowable
does it.static String
toLongString
(Map<?, ?> pairs) If you want to print the system properties as key-value pairs (e.g.static String
toResource
(Class<?> clazz) To resource.static String
To resource.static String
toShortString
(Number number) To short string.static String
toShortString
(Object obj) Converts an object to its toString representation.static String
toShortString
(Object[] array) To short string.static String
toShortString
(Time time) If the given time string has 0 seconds it is returned as "hh:mm".toSortedSet
(Enumeration<?> enumeration) Converts an Enumeration into a SortedSet.static String
Converts an object into its string representation.static String
An empty array or null is mapped to "[]" (empty array).static String
Maps an array to its string representation.static String
Converts a date to string using English as default locale.static String
toString
(LocalDateTime time, String pattern) Converts a date to string using English as default locale.static String
Converts a date to string using the default locale.static String
Converts a date to string using the default locale.static String
toString
(Enumeration<?> enumeration) To string.static String[]
toStringArray
(Object[] array) Each object inside the array is converted into its toString() representation.static String[]
toStringArray
(Set<Object> set) Each object inside the Set is converted into its toString() representation.static Time
Converts a time string to aTime
value.static URI
If a URL contains illegal characters for an URI (like blanks) this should be automatically converted (e.g. to "%20").static URI
If a URL contains illegal characters for an URI (like blanks) this should be automatically converted (e.g. to "%20")
-
Method Details
-
getMemoryAsString
Gets the memory as string.- Parameters:
mem
- the mem- Returns:
- the memory as string
-
getTimeAsString
Gets the time as string with the corresponding unit. Unit can be "ms" (for milliseconds) or "seconds".- Parameters:
timeInMillis
- the time in millis- Returns:
- the time as string
- Since:
- 1.2.20
-
getTimeAsString
Gets the time as string with the corresponding unit. Unit can be "ms" (for milliseconds) or "seconds".- Parameters:
timeInMillis
- the time in millis- Returns:
- the time as string
- Since:
- 1.4.2
-
getTimeAsString
-
classToResource
-
toResource
-
packageToResource
-
toResource
-
resourceToClass
-
toURI
-
toURI
If a URL contains illegal characters for an URI (like blanks) this should be automatically converted (e.g. to "%20"). Also URL starting without an authority element (like "file:/") cannot have two slash characters ("//"). This is also corrected- Parameters:
uri
- the URL to be converted- Returns:
- the given URL as URI
-
toFile
-
toFile
-
toAbsolutePath
-
toString
-
toString
To string.- Parameters:
enumeration
- the enumeration- Returns:
- the string
-
toShortString
Converts an object to its toString representation. If the resuulting string would be too long it will be abbreviated.If the resulting toString representation looks like the default implementation of
Object.toString()
the package name will be removed from the result. For other toString resultsStringUtils.abbreviate(String, int)
will be used to cut it if necessary.- Parameters:
obj
- the obj- Returns:
- the string
-
toShortString
-
toShortString
-
toLongString
-
toString
-
toString
-
toShortString
-
toLongString
-
toLongString
-
toLongString
This implementation prints the stacktrace in a similar way as the printStacktrace method ofThrowable
does it.- Parameters:
stacktrace
- the array- Returns:
- the string
- Since:
- 1.4.2
-
toStringArray
-
toStringArray
-
toString
-
toString
-
toString
Converts a date to string using English as default locale.- Parameters:
time
- a valid timepattern
- e.g. "dd-MMM-yyyy HH:mm"- Returns:
- e.g. "07-Jan-2022 17:40"
- Since:
- 1.1
-
toString
-
toArray
-
toDate
Converts a string to a date by trying different date patterns. If the string can't be converted an IllegalArgumentException will be thrown.- Parameters:
s
- e.g. "28-Nov-2009" or "Thu Nov 26 14:30:25 CET 2009"- Returns:
- a valid date or NULL_DATE (if an empty string is given)
-
toDate
Converts a string to a date with the help of the given pattern. If the string can't be converted an IllegalArgumentException will be thrown.- Parameters:
s
- e.g. "28-Nov-2009"pattern
- e.g. "dd-MMM-yyyy"- Returns:
- a valid date or NULL_DATE (if an empty string is given)
-
toTime
Converts a time string to aTime
value. In contradiction toTime.valueOf(String)
it works also if the time string is given in the format "hh:mm".- Parameters:
s
- e.g. "12:00" for high noon- Returns:
- the time
-
toSortedSet
Converts an Enumeration into a SortedSet.- Parameters:
enumeration
- the Enumeration- Returns:
- the SortedSet
- Since:
- 1.0
-
serialize
Serializes the given object and returns it as byte array.- Parameters:
object
- the object to be serialized- Returns:
- the object as byte array
- Throws:
NotSerializableException
- the not serializable exception
-
deserialize
Deserializes the given byte array and returns it as object.- Parameters:
bytes
- the byte array- Returns:
- the deserialized object
- Throws:
ClassNotFoundException
- if byte array can't be deserialized
-