@Internal public final class BinaryStringData extends LazyBinaryFormat<String> implements StringData
StringData
which is backed by MemorySegment
s
and String
.
Either MemorySegment
s or String
must be provided when constructing BinaryStringData
. The other representation will be materialized when needed.
It provides many useful methods for comparison, search, and so on.
Modifier and Type | Field and Description |
---|---|
static BinaryStringData |
EMPTY_UTF8 |
HIGHEST_FIRST_BIT, HIGHEST_SECOND_TO_EIGHTH_BIT, MAX_FIX_PART_DATA_SIZE
Constructor and Description |
---|
BinaryStringData() |
BinaryStringData(MemorySegment[] segments,
int offset,
int sizeInBytes) |
BinaryStringData(MemorySegment[] segments,
int offset,
int sizeInBytes,
String javaObject) |
BinaryStringData(String javaObject) |
Modifier and Type | Method and Description |
---|---|
static BinaryStringData |
blankString(int length)
Creates a
BinaryStringData instance that contains `length` spaces. |
byte |
byteAt(int index)
Returns the
byte value at the specified index. |
int |
compareTo(StringData o)
Compares two strings lexicographically.
|
boolean |
contains(BinaryStringData s)
Returns true if and only if this BinaryStringData contains the specified sequence of bytes
values.
|
BinaryStringData |
copy()
Copy a new
BinaryStringData . |
boolean |
endsWith(BinaryStringData suffix)
Tests if this BinaryStringData ends with the specified suffix.
|
void |
ensureMaterialized() |
boolean |
equals(Object o) |
static BinaryStringData |
fromAddress(MemorySegment[] segments,
int offset,
int numBytes)
Creates a
BinaryStringData instance from the given address (base and offset) and
length. |
static BinaryStringData |
fromBytes(byte[] bytes)
Creates a
BinaryStringData instance from the given UTF-8 bytes. |
static BinaryStringData |
fromBytes(byte[] bytes,
int offset,
int numBytes)
Creates a
BinaryStringData instance from the given UTF-8 bytes with offset and number
of bytes. |
static BinaryStringData |
fromString(String str)
Creates a
BinaryStringData instance from the given Java string. |
int |
getOffset()
Gets the start offset of this binary data in the
MemorySegment s. |
MemorySegment[] |
getSegments()
Gets the underlying
MemorySegment s this binary format spans. |
int |
getSizeInBytes()
Gets the size in bytes of this binary data.
|
int |
hashCode() |
int |
indexOf(BinaryStringData str,
int fromIndex)
Returns the index within this string of the first occurrence of the specified substring,
starting at the specified index.
|
protected BinarySection |
materialize(TypeSerializer<String> serializer)
Materialize java object to binary format.
|
int |
numChars()
Returns the number of UTF-8 code points in the string.
|
boolean |
startsWith(BinaryStringData prefix)
Tests if this BinaryStringData starts with the specified prefix.
|
BinaryStringData |
substring(int beginIndex,
int endIndex)
Returns a binary string that is a substring of this binary string.
|
byte[] |
toBytes()
Converts this
StringData object to a UTF-8 byte array. |
BinaryStringData |
toLowerCase()
Converts all of the characters in this
BinaryStringData to lower case. |
String |
toString()
Converts this
StringData object to a String . |
BinaryStringData |
toUpperCase()
Converts all of the characters in this
BinaryStringData to upper case. |
BinaryStringData |
trim()
Returns a string whose value is this string, with any leading and trailing whitespace
removed.
|
ensureMaterialized, getBinarySection, getJavaObject, setJavaObject
public static final BinaryStringData EMPTY_UTF8
public BinaryStringData()
public BinaryStringData(String javaObject)
public BinaryStringData(MemorySegment[] segments, int offset, int sizeInBytes)
public BinaryStringData(MemorySegment[] segments, int offset, int sizeInBytes, String javaObject)
public static BinaryStringData fromAddress(MemorySegment[] segments, int offset, int numBytes)
BinaryStringData
instance from the given address (base and offset) and
length.public static BinaryStringData fromString(String str)
BinaryStringData
instance from the given Java string.fromString
in interface StringData
public static BinaryStringData fromBytes(byte[] bytes)
BinaryStringData
instance from the given UTF-8 bytes.fromBytes
in interface StringData
public static BinaryStringData fromBytes(byte[] bytes, int offset, int numBytes)
BinaryStringData
instance from the given UTF-8 bytes with offset and number
of bytes.fromBytes
in interface StringData
public static BinaryStringData blankString(int length)
BinaryStringData
instance that contains `length` spaces.public byte[] toBytes()
StringData
StringData
object to a UTF-8 byte array.
Note: The returned byte array may be reused.
toBytes
in interface StringData
public String toString()
StringData
StringData
object to a String
.toString
in interface StringData
toString
in class Object
public int compareTo(@Nonnull StringData o)
compareTo
in interface Comparable<StringData>
public int numChars()
public byte byteAt(int index)
byte
value at the specified index. An index ranges from 0
to
binarySection.sizeInBytes - 1
.index
- the index of the byte
value.byte
value at the specified index of this UTF-8 bytes.IndexOutOfBoundsException
- if the index
argument is negative or not less
than the length of this UTF-8 bytes.public MemorySegment[] getSegments()
BinaryFormat
MemorySegment
s this binary format spans.getSegments
in interface BinaryFormat
getSegments
in class LazyBinaryFormat<String>
public int getOffset()
BinaryFormat
MemorySegment
s.getOffset
in interface BinaryFormat
getOffset
in class LazyBinaryFormat<String>
public int getSizeInBytes()
BinaryFormat
getSizeInBytes
in interface BinaryFormat
getSizeInBytes
in class LazyBinaryFormat<String>
public void ensureMaterialized()
protected BinarySection materialize(TypeSerializer<String> serializer)
LazyBinaryFormat
RawValueData
needs javaObjectSerializer).materialize
in class LazyBinaryFormat<String>
public BinaryStringData copy()
BinaryStringData
.public BinaryStringData substring(int beginIndex, int endIndex)
beginIndex
and extends to the character at index endIndex - 1
.
Examples:
fromString("hamburger").substring(4, 8) returns binary string "urge" fromString("smiles").substring(1, 5) returns binary string "mile"
beginIndex
- the beginning index, inclusive.endIndex
- the ending index, exclusive.public boolean contains(BinaryStringData s)
s
- the sequence to search fors
, false otherwisepublic boolean startsWith(BinaryStringData prefix)
prefix
- the prefix.true
if the bytes represented by the argument is a prefix of the bytes
represented by this string; false
otherwise. Note also that true
will be
returned if the argument is an empty BinaryStringData or is equal to this BinaryStringData
object as determined by the equals(Object)
method.public boolean endsWith(BinaryStringData suffix)
suffix
- the suffix.true
if the bytes represented by the argument is a suffix of the bytes
represented by this object; false
otherwise. Note that the result will be true
if the argument is the empty string or is equal to this BinaryStringData
object as determined by the equals(Object)
method.public BinaryStringData trim()
public int indexOf(BinaryStringData str, int fromIndex)
str
- the substring to search for.fromIndex
- the index from which to start the search.-1
if there is no such occurrence.public BinaryStringData toUpperCase()
BinaryStringData
to upper case.BinaryStringData
, converted to uppercase.public BinaryStringData toLowerCase()
BinaryStringData
to lower case.BinaryStringData
, converted to lowercase.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.