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
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) intbooleanintReturn length in bytes.byte[]getBytes()Return UTF-8 encoded bytes.static byte[]getBytesFor(String str) Gets the UTF-8 bytes for a StringintDeprecated.inthashCode()intlength()voidSet 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()voidMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<Utf8>
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
getBytesFor
Gets the UTF-8 bytes for a String -
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
getByteLength()instead.