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) static intcompareSequences(CharSequence cs1, CharSequence cs2) intbooleanintReturn length in bytes.byte[]getBytes()Return UTF-8 encoded bytes.static byte[]getBytesFor(String str) Gets the UTF-8 bytes for a StringinthashCode()intlength()voidSet to the contents of a String.setByteLength(int newLength) Set length in bytes.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()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:
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
-
compareSequences
-