Class Converter
java.lang.Object
clazzfish.monitor.util.Converter
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringclassToResource(String name) Converts a classname (e.g.static Serializabledeserialize(byte[] bytes) Deserializes the given byte array and returns it as object.static StringgetMemoryAsString(long mem) Gets the memory as string.static StringgetTimeAsString(double timeInMillis) Gets the time as string with the corresponding unit.static StringgetTimeAsString(double timeInMillis, Locale locale) Gets the time as string with the corresponding unit.static StringgetTimeAsString(long timeInMillis) Gets the time as string with the corresponding unit.static StringpackageToResource(String name) Converts a package name (e.g.static StringresourceToClass(String name) Converts a resource (e.g.static byte[]serialize(Serializable object) Serializes the given object and returns it as byte array.static StringtoAbsolutePath(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 DateConverts a string to a date by trying different date patterns.static DateConverts a string to a date with the help of the given pattern.static FileConverts an URI into a file.static FileConverts an URI into a file.static StringtoLongString(Object obj) Converts an object into a long representation as the normal toString method.static StringtoLongString(Object[] array) If you want to print each element of an array into a single line you can use this method here.static StringtoLongString(StackTraceElement[] stacktrace) This implementation prints the stacktrace in a similar way as the printStacktrace method ofThrowabledoes it.static StringtoLongString(Map<?, ?> pairs) If you want to print the system properties as key-value pairs (e.g.static StringtoResource(Class<?> clazz) To resource.static StringTo resource.static StringtoShortString(Number number) To short string.static StringtoShortString(Object obj) Converts an object to its toString representation.static StringtoShortString(Object[] array) To short string.static StringtoShortString(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 StringConverts an object into its string representation.static StringAn empty array or null is mapped to "[]" (empty array).static StringMaps an array to its string representation.static StringConverts a date to string using English as default locale.static StringtoString(LocalDateTime time, String pattern) Converts a date to string using English as default locale.static StringConverts a date to string using the default locale.static StringConverts a date to string using the default locale.static StringtoString(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 TimeConverts a time string to aTimevalue.static URIIf a URL contains illegal characters for an URI (like blanks) this should be automatically converted (e.g. to "%20").static URIIf 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 ofThrowabledoes 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 aTimevalue. 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
-