Package it.unimi.dsi.law.warc.util
Class ByteArrayCharSequence
java.lang.Object
it.unimi.dsi.law.warc.util.ByteArrayCharSequence
- All Implemented Interfaces:
CharSequence
public class ByteArrayCharSequence extends Object implements CharSequence
An adapter exposing a byte array as an ISO-8859-1-encoded
character sequence.
An instance of this adapter can be reused by wrapping a new byte array.
Note that for convenience this class exposes a hashCode()
method that
return the same result as String
, but equality is not by content.
-
Constructor Summary
Constructors Constructor Description ByteArrayCharSequence()
Creates a new empty byte-array character sequence.ByteArrayCharSequence(byte[] b)
Creates a new byte-array character sequence using the provided byte array.ByteArrayCharSequence(byte[] b, int offset, int length)
Creates a new byte-array character sequence using the provided byte-array fragment. -
Method Summary
Modifier and Type Method Description char
charAt(int index)
int
hashCode()
int
length()
CharSequence
subSequence(int start, int end)
String
toString()
void
wrap(byte[] b)
Wraps a byte array into this byte-array character sequence.ByteArrayCharSequence
wrap(byte[] b, int offset, int length)
Wraps a byte-array fragment into this byte-array character sequence.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
ByteArrayCharSequence
public ByteArrayCharSequence(byte[] b, int offset, int length)Creates a new byte-array character sequence using the provided byte-array fragment.- Parameters:
b
- a byte array.offset
- the first valid byte inb
.length
- the number of valid bytes inb
, starting atoffset
.
-
ByteArrayCharSequence
public ByteArrayCharSequence(byte[] b)Creates a new byte-array character sequence using the provided byte array.- Parameters:
b
- a byte array.
-
ByteArrayCharSequence
public ByteArrayCharSequence()Creates a new empty byte-array character sequence.
-
-
Method Details
-
wrap
Wraps a byte-array fragment into this byte-array character sequence.- Parameters:
b
- a byte array.offset
- the first valid byte inb
.length
- the number of valid bytes inb
, starting atoffset
.- Returns:
- this byte-array character sequence.
-
wrap
public void wrap(byte[] b)Wraps a byte array into this byte-array character sequence.- Parameters:
b
- a byte array.
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index)- Specified by:
charAt
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
hashCode
public int hashCode()
-