com.twistedmatrix.util
Class ByteString
java.lang.Object
|
+--com.twistedmatrix.util.ByteString
- public class ByteString
- extends java.lang.Object
A byte array that is immutable and can be used as key in Map.
Two ByteStrings with the same contents should have the same hashCode()
and be equals().
This class is similar in intent to CPython strings.
Field Summary |
protected byte[] |
bytes
|
Constructor Summary |
ByteString(byte[] bytes)
Create a new ByteString from a byte array. |
ByteString(java.lang.String str)
Create a new ByteString from a String encoded in ASCII. |
Method Summary |
boolean |
equals(java.lang.Object obj)
|
byte[] |
getBytes()
Get the bytes of the ByteString. |
int |
getLength()
Get the length of the ByteString. |
int |
hashCode()
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
bytes
protected byte[] bytes
ByteString
public ByteString(byte[] bytes)
- Create a new ByteString from a byte array.
- Parameters:
bytes
- an array of bytes which should not be changed once we created the ByteString.
ByteString
public ByteString(java.lang.String str)
- Create a new ByteString from a String encoded in ASCII.
- Parameters:
str
- an ASCII string.
getLength
public int getLength()
- Get the length of the ByteString.
getBytes
public byte[] getBytes()
- Get the bytes of the ByteString.
DO NOT CHANGE THE RESULTING ARRAY.
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in class java.lang.Object
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object