Package com.backblaze.b2.util
Class B2StringUtil
- java.lang.Object
-
- com.backblaze.b2.util.B2StringUtil
-
public class B2StringUtil extends java.lang.Object
String utilities
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
UTF8
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
decimalNumberInRange(java.lang.String str, int offset, int length, int minInclusive, int maxInclusive)
static int
decimalSubstringToInt(java.lang.String s, int startIndex, int endIndex)
static byte[]
getUtf8Bytes(java.lang.String str)
Returns the UTF-8 representation of a string.static boolean
isEmpty(java.lang.String str)
static java.lang.String
join(java.lang.String delimiter, java.lang.Object[] objects)
static java.lang.String
percentDecode(java.lang.String s)
static java.lang.String
percentEncode(java.lang.String s)
static boolean
startsWithIgnoreCase(java.lang.String all, java.lang.String possiblePrefix)
static java.lang.String
toHexString(byte[] b)
static java.lang.String
underscoresToCamelCase(java.lang.String orig, boolean capitalizeFirstLetter)
This returns a new string with the first letter title-cased, and first character after each "_" title-cased, and all underscores removed.
-
-
-
Field Detail
-
UTF8
public static final java.lang.String UTF8
- See Also:
- Constant Field Values
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(java.lang.String str)
- Parameters:
str
- the string to check- Returns:
- true if str is null or zero-length.
-
percentEncode
public static java.lang.String percentEncode(java.lang.String s)
- Parameters:
s
- the string to encode.- Returns:
- a string with the contents of 's' encoded with percents as is done for URLs.
-
percentDecode
public static java.lang.String percentDecode(java.lang.String s)
-
decimalSubstringToInt
public static int decimalSubstringToInt(java.lang.String s, int startIndex, int endIndex)
- Parameters:
s
- the string to examinestartIndex
- the index of the first character to examineendIndex
- the index just past the last character to examine. must be >= startIndex.- Returns:
- 0 if beginIndex == endIndex, otherwise the specified substring of 's' as an integer.
- Throws:
java.lang.IllegalArgumentException
- if the substring doesn't represent an integer.
-
decimalNumberInRange
public static boolean decimalNumberInRange(java.lang.String str, int offset, int length, int minInclusive, int maxInclusive)
- Parameters:
str
- the string to examineoffset
- index of the first character to examine. must be >= 0.length
- the length of the substring to examine. must be >= 0.minInclusive
- the smallest value allowedmaxInclusive
- the largest value allowed- Returns:
- true iff the specified substring of 'str' is an integer in the specified range.
-
join
public static java.lang.String join(java.lang.String delimiter, java.lang.Object[] objects)
-
getUtf8Bytes
public static byte[] getUtf8Bytes(java.lang.String str)
Returns the UTF-8 representation of a string. We assume that there's always a UTF-8 charset installed, and it's a bother to catch the exception everywhere, so this method catches the exception for you.
-
toHexString
public static java.lang.String toHexString(byte[] b)
- Parameters:
b
- the array of bytes to convert.- Returns:
- if b is null or empty, "". otherwise, returns a string with two lowercase hex digits for each byte in the string, representing the value of that byte.
-
underscoresToCamelCase
public static java.lang.String underscoresToCamelCase(java.lang.String orig, boolean capitalizeFirstLetter)
This returns a new string with the first letter title-cased, and first character after each "_" title-cased, and all underscores removed. For example, "foo" becomes "Foo" and "foo_bar_baz" becomes "FooBarBaz".- Parameters:
orig
- an input string with "_"s separating words.capitalizeFirstLetter
- should the first letter be capitalized?- Returns:
- new, camel-cased version of orig
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(java.lang.String all, java.lang.String possiblePrefix)
- Parameters:
all
- the string whose prefix we're checkingpossiblePrefix
- the prefix we're asking about being in all.- Returns:
- true iff both all and possiblePrefix are non-null and all starts with possiblePrefix ignoring case.
-
-