com.vertica.sdk.StringUtils Class Reference
Collaboration diagram for com.vertica.sdk.StringUtils:
| Static Public Member Functions | |
|---|---|
| static ByteBuffer | duplicateBB (ByteBuffer buffer) |
| static Charset | getCharset () |
| static ByteBuffer | getStringBytes (String value, int length, boolean removeTrailingSpaces) |
| static ByteBuffer | getStringBytes (String value, int length, boolean removeTrailingSpaces, boolean truncate) |
| static String | newString (ByteBuffer buffer) |
| static String | newString (ByteBuffer buffer, Charset charset) |
| static void | removeTruncatedUtf8CharBytes (ByteBuffer string) |
| static ByteBuffer | sliceBB (ByteBuffer buffer) |
Detailed Description
A collection of string-related functions which assist in reading, generating, and handling Vertica string-like types. String-like types include:
-
char
-
varchar
-
long varchar
-
binary
-
varbinary
-
long varbinary
Member Function Documentation
◆duplicateBB()
static ByteBuffer com.vertica.sdk.StringUtils.duplicateBB(ByteBuffer buffer)
static
A safer version of ByteBuffer#duplicate() that works around weird Java behavior. ByteBuffer#duplicate() does not apply the byte ordering of the source buffer to the duplicate buffer. This helper handles this. Otherwise it is identical.
Parameters
buffer: A non-null ByteBuffer.
Returns a duplicate of the given buffer, sharing the same storage.
See also
Referenced by
- com.vertica.sdk.VString.data()
- com.vertica.sdk.vmap.v1.Encoder.encode()
- com.vertica.sdk.VerticaBlock.getInlineColBuffer()
◆getCharset()
static Charset com.vertica.sdk.StringUtils.getCharset()
static
Get the Charset used by Vertica. Required for any strings stored within or retrieved from Vertica.
Returns The character set.
Referenced by
- com.vertica.sdk.VString.copy()
- com.vertica.sdk.StringUtils.getStringBytes()
- com.vertica.sdk.StringUtils.newString()
- com.vertica.sdk.VString.str()
◆getStringBytes() [1/2]
static ByteBuffer com.vertica.sdk.StringUtils.getStringBytes(String value, int length, boolean removeTrailingSpaces)
static
Correctly extract the bytes from a Java String in Vertica's character set. Does not perform truncation. Shorthand for:
getStringBytes(value, length, removeTrailingSpaces, false);
See also
Parameters
value: A non-null String (may be empty)length: The maximum byte length of the destination, or -1 for no maximum.removeTrailingSpaces: If true, trailing ASCII spaces will be excluded from the resulting byte sequence. This is proper behavior for Vertica's 'char' type.
Returns a ByteBuffer with position and limit designating the start and end of the correct byte representation of the string. If truncation is not permitted and the value is too long, null will be returned.
Referenced by
◆getStringBytes() [2/2]
static ByteBuffer com.vertica.sdk.StringUtils.getStringBytes(String value, int length, boolean removeTrailingSpaces, boolean truncate)
static
Correctly extract the bytes from a Java String in Vertica's character set. This ensures that the value fits within the designated byte length OR is properly truncated.
If truncation falls within a multi-byte character, additional bytes will be removed in order to ensure the contents are a valid string encoding. This can cause truncation to result in byte buffer that is shorter than length.
When applicable, trailing spaces are removed from the input string immediately as well as after truncation. Therefore, values that exceed the maximum length due to trailing spaces will not require truncation. Also, values that are truncated (if applicable) will have any remaining trailing spaces removed.
See also
Parameters
value: A non-null String (may be empty)length: The maximum byte length of the destination, or -1 for no maximum.removeTrailingSpaces: If true, trailing ASCII spaces will be excluded from the resulting byte sequence. This is proper behavior for Vertica's 'char' type.truncate: If true, truncate values that are too long. If false, return null for values that are too long.
Returns a ByteBuffer with position and limit designating the start and end of the correct byte representation of the string. If truncation is not permitted and the value is too long, null will be returned.
◆newString() [1/2]
static String com.vertica.sdk.StringUtils.newString(ByteBuffer buffer)
static
Decode a String from the ByteBuffer using Vertica's charset. This is written to avoid unnecessary copies of the byte data. The buffer is not modified.
Parameters
buffer: The buffer with String bytes between its position and limit. The position and limit of the buffer is left unmodified. May not be null.
See also
Returns a non-null String
◆newString() [2/2]
static String com.vertica.sdk.StringUtils.newString(ByteBuffer buffer, Charset charset)
static
Decode a String from the ByteBuffer using the specified charset. The implementation avoids unnecessary copies of the byte data.
Parameters
buffer: The buffer with String bytes between its position and limit. The position and limit of the buffer is left unmodified. May not be null.charset: The Charset to use when creating the new string from the source bytes.
Returns a non-null String
◆removeTruncatedUtf8CharBytes()
static void com.vertica.sdk.StringUtils.removeTruncatedUtf8CharBytes(ByteBuffer string)
static
Removes bytes at the end of a string encoded in Vertica's character set that are incomplete multi-byte characters. This scenario usually occurs due to truncation according to byte length which falls in the middle of a multi-byte character. This further truncation ensures the final string is valid in Vertica's encoding.
Parameters
string: A ByteBuffer representing a string in Vertica's encoding. The limit will be moved towards the position in order to drop partial multi-byte characters.
Referenced by com.vertica.sdk.StringUtils.getStringBytes().
◆sliceBB()
static ByteBuffer com.vertica.sdk.StringUtils.sliceBB(ByteBuffer buffer)
static
A safer version of ByteBuffer#slice() that works around weird Java behavior. ByteBuffer#slice() does not apply the byte ordering of the source buffer to the slice buffer. This helper handles this. Otherwise it is identical.
Parameters
buffer: A non-null ByteBuffer.
Returns a view into the given buffer, sharing the same storage.
See also
Referenced by