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
hashCode()
int
length()
void
Set to the contents of a String.setByteLength
(int newLength) Set length in bytes.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()
assuming the bytes have been fully copied into the underlying buffer from the source.- Returns:
- a reference to the underlying byte array
- See Also:
-
getByteLength
public int getByteLength()Return length in bytes. -
setByteLength
Set length in bytes. When calling this method, even if the new length is the same as the current length, the cached contents of this Utf8 object will be wiped out. After calling this method, no assumptions should be made about the internal state (e.g., contents, hashcode, equality, etc.) of this Utf8 String other than the internal buffer being large enough to accommodate a String of the new length. This should be called immediately before reading a String from the underlying data source.- Parameters:
newLength
- the new length of the underlying buffer- Returns:
- a reference to this object.
- See Also:
-
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
-