Package com.castlabs.utils
Class StringUtils
java.lang.Object
com.castlabs.utils.StringUtils
String utilities and formats
- Since:
- 2.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdurationStrToMinString(String durationStr) Convert a string formatted as "PnYnMnDTnHnMnS" (as defined by XML Schema Part 2: Datatypes, 3.2.6 duration) into a string formatted as "M" (ie.static StringdurationStrToTimeString(String contentRunLength) Convert a string formatted as "PnYnMnDTnHnMnS" (as defined by XML Schema Part 2: Datatypes, 3.2.6 duration) into a string formatted as"H+:MM:SS"static StringTries safely to format the string using the provided locale and format.static Stringjoin(Collection<String> tokens, String delimiter) Join a list of token using teh given delimiterstatic StringstringForBitrate(int bitrate) Formats a given bitrate as bps, Kbps, or Mbps.static StringstringForBitrate(long bitrate) Formats a given bitrate as bps, Kbps, or Mbps.static StringstringForComputerSize(long sizeInBytes) Convert the size in bytes into a string typed as "x.xx bytes", "x.xx KB" or "x.xx MB" or "x.xx GB"static StringstringForTime(long totalSeconds) Convert the time in seconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or notstatic StringstringForTime(long totalSeconds, boolean forceHoursDisplay) Convert the time in seconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or not or the hour format is forced.static StringstringForTime(long time, TimeUnit unit) Convert the time in seconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or notstatic StringstringForTimeMs(long timeMs, boolean forceHoursDisplay, boolean showMillis) Convert the time in milliseconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or not or the hour format is forced.
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
stringForTime
Convert the time in seconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or not- Parameters:
time- durations in secondsunit- The time unit- Returns:
- formatted time string in the form "mm:ss: or "hh:mm:ss"
- See Also:
-
stringForTime
Convert the time in seconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or not- Parameters:
totalSeconds- durations in seconds- Returns:
- formatted time string in the form "mm:ss: or "hh:mm:ss"
- See Also:
-
stringForTime
Convert the time in seconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or not or the hour format is forced. If seconds is negative, the formatted string will be prefixed with "-".- Parameters:
totalSeconds- duration in secondsforceHoursDisplay- force "hh:mm:ss" display- Returns:
- formatted time string in the form "mm:ss: or "hh:mm:ss"
-
stringForTimeMs
Convert the time in milliseconds into a string type as "hh:mm:ss" or "mm:ss" depending on the duration being >= 1h or not or the hour format is forced. Milliseconds can also be added to the output. If seconds is negative, the formatted string will be prefixed with "-".- Parameters:
timeMs- duration in millisecondsforceHoursDisplay- force "hh:mm:ss" displayshowMillis- render milliseconds as "hh:mm:ss.MMM" display- Returns:
- formatted time string in the form "mm:ss or "hh:mm:ss"
-
stringForComputerSize
Convert the size in bytes into a string typed as "x.xx bytes", "x.xx KB" or "x.xx MB" or "x.xx GB"- Parameters:
sizeInBytes- the size in bytes- Returns:
- foramated size
-
stringForBitrate
Formats a given bitrate as bps, Kbps, or Mbps.- Parameters:
bitrate- The bitrate in bits per second- Returns:
- The formatted string representation
-
stringForBitrate
Formats a given bitrate as bps, Kbps, or Mbps.- Parameters:
bitrate- The bitrate in bits per second- Returns:
- The formatted string representation
-
join
Join a list of token using teh given delimiter- Parameters:
tokens- the list of tokensdelimiter- the delimiter- Returns:
- joined string
-
durationStrToTimeString
Convert a string formatted as "PnYnMnDTnHnMnS" (as defined by XML Schema Part 2: Datatypes, 3.2.6 duration) into a string formatted as"H+:MM:SS"- Parameters:
contentRunLength- the duration string- Returns:
- time string formatted as"H+:MM:SS"
- Throws:
Exception- in case of an error during conversion
-
durationStrToMinString
Convert a string formatted as "PnYnMnDTnHnMnS" (as defined by XML Schema Part 2: Datatypes, 3.2.6 duration) into a string formatted as "M" (ie. only minutes)- Parameters:
durationStr- duration string- Returns:
- formatted string
- Throws:
Exception- in case of an error during conversion
-
format
Tries safely to format the string using the provided locale and format. When exception occurs then the default locale is used instead and in case of error thenullis returned finally.- Parameters:
locale- The locale to be used in the first placeformat- The formatargs- The arguments to format- Returns:
- Formatted
Stringornullif error occurs
-