Package org.apache.avro.util
Class Utf8
java.lang.Object
org.apache.avro.util.Utf8
- All Implemented Interfaces:
Externalizable
,Serializable
,CharSequence
,Comparable<Utf8>
A Utf8 string. Unlike
String
, instances are mutable. This is more
efficient than String
when reading or writing a sequence of values,
as a single instance may be reused.- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) int
boolean
int
Return length in bytes.byte[]
getBytes()
Return UTF-8 encoded bytes.static byte[]
getBytesFor
(String str) Gets the UTF-8 bytes for a Stringint
Deprecated.int
hashCode()
int
length()
void
Set to the contents of a String.setByteLength
(int newLength) Set length in bytes.setLength
(int newLength) Deprecated.callsetByteLength(int)
instead.subSequence
(int start, int end) toString()
void
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
Constructor Details
-
Utf8
public Utf8() -
Utf8
-
Utf8
-
Utf8
public Utf8(byte[] bytes)
-
-
Method Details
-
getBytes
public byte[] getBytes()Return UTF-8 encoded bytes. Only valid throughgetByteLength()
. -
getLength
Deprecated.callgetByteLength()
instead.Return length in bytes. -
getByteLength
public int getByteLength()Return length in bytes. -
setLength
Deprecated.callsetByteLength(int)
instead.Set length in bytes. Should called whenever byte content changes, even if the length does not change, as this also clears the cached String. -
setByteLength
Set length in bytes. Should called whenever byte content changes, even if the length does not change, as this also clears the cached String. -
set
Set to the contents of a String. -
set
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<Utf8>
-
charAt
public char charAt(int index) - Specified by:
charAt
in interfaceCharSequence
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
getBytesFor
Gets the UTF-8 bytes for a String -
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
getByteLength()
instead.