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 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 in b.
      length - the number of valid bytes in b, starting at offset.
    • 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

      public ByteArrayCharSequence wrap​(byte[] b, int offset, int length)
      Wraps a byte-array fragment into this byte-array character sequence.
      Parameters:
      b - a byte array.
      offset - the first valid byte in b.
      length - the number of valid bytes in b, starting at offset.
      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 interface CharSequence
    • charAt

      public char charAt​(int index)
      Specified by:
      charAt in interface CharSequence
    • subSequence

      public CharSequence subSequence​(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object