Java SDK Documentation  12.0.0
com.vertica.sdk.StringUtils Class Reference
Collaboration diagram for com.vertica.sdk.StringUtils:
Collaboration graph

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

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
bufferA non-null ByteBuffer.
Returns
a duplicate of the given buffer, sharing the same storage.
See Also
Java bug 4715166

Referenced by com.vertica.sdk.vmap.v1.Encoder.encode().

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(), and com.vertica.sdk.StringUtils.newString().

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
getCharset()
Parameters
valueA non-null String (may be empty)
lengthThe maximum byte length of the destination, or -1 for no maximum.
removeTrailingSpacesIf 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.
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
getCharset()
Parameters
valueA non-null String (may be empty)
lengthThe maximum byte length of the destination, or -1 for no maximum.
removeTrailingSpacesIf true, trailing ASCII spaces will be excluded from the resulting byte sequence. This is proper behavior for Vertica's 'char' type.
truncateIf 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.
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
bufferThe 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
getCharset()
Returns
a non-null String
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
bufferThe buffer with String bytes between its position and limit. The position and limit of the buffer is left unmodified. May not be null.
charsetThe Charset to use when creating the new string from the source bytes.
Returns
a non-null String
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
stringA 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().

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
bufferA non-null ByteBuffer.
Returns
a view into the given buffer, sharing the same storage.
See Also
Java bug 4715166