Class Util
java.lang.Object
com.castlabs.sdk.base.subtitles.utilities.Util
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringLikeBuild.DEVICE, but in a place where it can be conveniently overridden for local testing.static final StringA concise description of the device that it can be useful to log for debugging purposes.static final byte[]An empty byte array.static final StringLikeBuild.MANUFACTURER, but in a place where it can be conveniently overridden for local testing.static final StringLikeBuild.MODEL, but in a place where it can be conveniently overridden for local testing.static final intLikeBuild.VERSION.SDK_INT, but in a place where it can be conveniently overridden for local testing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanTests two objects forObject.equals(Object)equality, handling the case where one or both may be null.static <T> TcastNonNull(T value) Casts a nullable variable to a non-null variable without runtime null check.static StringfromUtf8Bytes(byte[] bytes) Returns a newStringconstructed by decoding UTF-8 encoded bytes.static StringfromUtf8Bytes(byte[] bytes, int offset, int length) Returns a newStringconstructed by decoding UTF-8 encoded bytes in a subarray.static StringgetCodecsOfType(String codecs, int trackType) Returns a copy ofcodecswithout the codecs whose track type doesn't matchtrackType.static intgetIntegerCodeForString(String string) Returns the integer equal to the big-endian concatenation of the characters instringas bytes.static byte[]getUtf8Bytes(String value) Returns a new byte array containing the code points of aStringencoded using UTF-8.static booleanisLinebreak(int c) Returns whether the given character is a carriage return ('\r') or a line feed ('\n').static <T> T[]nullSafeArrayConcatenation(T[] first, T[] second) Creates a new array containing the concatenation of two non-null type arrays.static String[]Splits a string usingvalue.split(regex, -1).static String[]splitAtFirst(String value, String regex) Splits the string at the first occurrence of the delimiterregex.static String[]splitCodecs(String codecs) Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings.static longtoLong(int mostSignificantBits, int leastSignificantBits) Return the long that is composed of the bits of the 2 specified integers.static @PolyNull StringtoLowerInvariant(@PolyNull String text) Converts text to lower case usingLocale.US.static longtoUnsignedLong(int x) Converts an integer to a long by unsigned conversion.static @PolyNull StringtoUpperInvariant(@PolyNull String text) Converts text to upper case usingLocale.US.
-
Field Details
-
SDK_INT
public static final int SDK_INTLikeBuild.VERSION.SDK_INT, but in a place where it can be conveniently overridden for local testing. -
DEVICE
LikeBuild.DEVICE, but in a place where it can be conveniently overridden for local testing. -
MANUFACTURER
LikeBuild.MANUFACTURER, but in a place where it can be conveniently overridden for local testing. -
MODEL
LikeBuild.MODEL, but in a place where it can be conveniently overridden for local testing. -
DEVICE_DEBUG_INFO
A concise description of the device that it can be useful to log for debugging purposes. -
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAYAn empty byte array.
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
splitCodecs
Splits a codecs sequence string, as defined in RFC 6381, into individual codec strings.- Parameters:
codecs- A codec sequence string, as defined in RFC 6381.- Returns:
- The split codecs, or an array of length zero if the input was empty or null.
-
split
Splits a string usingvalue.split(regex, -1). Note: this is is similar toString.split(String)but empty matches at the end of the string will not be omitted from the returned array.- Parameters:
value- The string to split.regex- A delimiting regular expression.- Returns:
- The array of strings resulting from splitting the string.
-
splitAtFirst
Splits the string at the first occurrence of the delimiterregex. If the delimiter does not match, returns an array with one element which is the input string. If the delimiter does match, returns an array with the portion of the string before the delimiter and the rest of the string.- Parameters:
value- The string.regex- A delimiting regular expression.- Returns:
- The string split by the first occurrence of the delimiter.
-
isLinebreak
public static boolean isLinebreak(int c) Returns whether the given character is a carriage return ('\r') or a line feed ('\n').- Parameters:
c- The character.- Returns:
- Whether the given character is a linebreak.
-
toLowerInvariant
Converts text to lower case usingLocale.US.- Parameters:
text- The text to convert.- Returns:
- The lower case text, or null if
textis null.
-
toUpperInvariant
Converts text to upper case usingLocale.US.- Parameters:
text- The text to convert.- Returns:
- The upper case text, or null if
textis null.
-
nullSafeArrayConcatenation
public static <T> T[] nullSafeArrayConcatenation(T[] first, T[] second) Creates a new array containing the concatenation of two non-null type arrays.- Parameters:
first- The first array.second- The second array.- Returns:
- The concatenated result.
-
castNonNull
@EnsuresNonNull("#1") public static <T> T castNonNull(@Nullable T value) Casts a nullable variable to a non-null variable without runtime null check.Use
Assertions.checkNotNull(Object)to throw if the value is null. -
areEqual
Tests two objects forObject.equals(Object)equality, handling the case where one or both may be null.- Parameters:
o1- The first object.o2- The second object.- Returns:
o1 == null ? o2 == null : o1.equals(o2).
-
getCodecsOfType
Returns a copy ofcodecswithout the codecs whose track type doesn't matchtrackType.- Parameters:
codecs- A codec sequence string, as defined in RFC 6381.trackType- One ofConstants.TRACK_TYPE_*.- Returns:
- A copy of
codecswithout the codecs whose track type doesn't matchtrackType. If this ends up empty, orcodecsis null, return null.
-
getIntegerCodeForString
Returns the integer equal to the big-endian concatenation of the characters instringas bytes. The string must be no more than four characters long.- Parameters:
string- A string no more than four characters long.
-
toLong
public static long toLong(int mostSignificantBits, int leastSignificantBits) Return the long that is composed of the bits of the 2 specified integers.- Parameters:
mostSignificantBits- The 32 most significant bits of the long to return.leastSignificantBits- The 32 least significant bits of the long to return.- Returns:
- a long where its 32 most significant bits are
mostSignificantBitsbits and its 32 least significant bits areleastSignificantBits.
-
toUnsignedLong
public static long toUnsignedLong(int x) Converts an integer to a long by unsigned conversion.This method is equivalent to
Integer.toUnsignedLong(int)for API 26+. -
fromUtf8Bytes
Returns a newStringconstructed by decoding UTF-8 encoded bytes.- Parameters:
bytes- The UTF-8 encoded bytes to decode.- Returns:
- The string.
-
fromUtf8Bytes
Returns a newStringconstructed by decoding UTF-8 encoded bytes in a subarray.- Parameters:
bytes- The UTF-8 encoded bytes to decode.offset- The index of the first byte to decode.length- The number of bytes to decode.- Returns:
- The string.
-
getUtf8Bytes
Returns a new byte array containing the code points of aStringencoded using UTF-8.- Parameters:
value- TheStringwhose bytes should be obtained.- Returns:
- The code points encoding using UTF-8.
-