Class ByteList

java.lang.Object
org.jruby.util.ByteList
All Implemented Interfaces:
Serializable, CharSequence, Comparable

public class ByteList extends Object implements Comparable, CharSequence, Serializable
ByteList is simple a collection of bytes in the same way a Java String is a collection of characters. However, its API resembles StringBuffer/StringBuilder more than String because it is a mutable object.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Deprecated.
    byte[]
    Deprecated.
    static final ByteList
     
    static final byte[]
     
    int
    Deprecated.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of ByteList
    ByteList(byte[] wrap)
    Create a new instance of ByteList with the contents of wrap.
    ByteList(byte[] wrap, boolean copy)
    Create a new instance of ByteList with the contents of wrap.
    ByteList(byte[] wrap, int index, int len)
    Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is.
    ByteList(byte[] wrap, int index, int len, boolean copy)
    Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is.
    ByteList(byte[] wrap, int index, int len, org.jcodings.Encoding encoding, boolean copy)
    Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is.
    ByteList(byte[] bytes, org.jcodings.Encoding encoding)
    Create a new instance of ByteList with the bytes supplied using the specified encoding.
    ByteList(byte[] wrap, org.jcodings.Encoding encoding, boolean copy)
    Create a new instance of ByteList with the contents of wrap.
    ByteList(int size)
    Creates a new instance of Bytelist with a pre-allocated size.
    ByteList(int size, org.jcodings.Encoding enc)
    Creates a new instance of Bytelist with a pre-allocated size and specified encoding.
    Create a new instance of byte list with the same contents as the passed in ByteList wrap.
    ByteList(ByteList wrap, int index, int len)
    Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(byte b)
    Append a single byte to the ByteList
    void
    append(byte[] moreBytes)
    Append moreBytes onto the end of the current ByteList.
    void
    append(byte[] moreBytes, int start, int len)
    Append moreBytes onto the end of the current ByteList with start as the new begin for len bytes from the moreBytes byte array.
    append(int b)
    Append a single byte to the ByteList by truncating the given int
    append(InputStream input, int len)
    Append up to length bytes from InputStream to the ByteList.
    void
    append(ByteBuffer buffer, int len)
    Append contents of the supplied nio ByteList up to len length onto the end of this ByteBuffer.
    void
    append(ByteList moreBytes)
    Append moreBytes onto the end of the current ByteList.
    void
    append(ByteList moreBytes, int index, int len)
    Append moreBytes onto the end of the current ByteList with +index as the new begin for len bytes from the moreBytes ByteList.
    int
    First index of the backing array that contains data for the ByteList.
    byte[]
    Get a copy of the bytes referenced by this ByteList.
    int
    Do a case insensitive comparison with other ByteList with return types similiar to compareTo.
    char
    charAt(int ix)
    Pretend byte array is raw and each byte is also the character value
     
    int
    cmp(ByteList other)
    This comparison matches MRI comparison of Strings (rb_str_cmp).
    int
    This comparison matches MRI comparison of Strings (rb_str_cmp).
    static ByteList
    Create a bytelist with ISO_8859_1 encoding from the provided CharSequence.
    static String
    decode(byte[] data, int offset, int length, String charsetName)
    Decode byte data into a String with the supplied charsetName.
    static String
    decode(byte[] data, String charsetName)
    Decode byte data into a String with the supplied charsetName.
    void
    delete(int start, int len)
    Delete len bytes from start index.
    dup()
    creates a duplicate of this bytelist but only in the case of a stringValue and its resulting hash value.
    dup(int length)
     
    static byte[]
    encode(CharSequence data, String charsetName)
    Encode CharSequence into a set of bytes based on the charsetName.
    boolean
    Does this ByteList end with the supplied ByteList?
    void
    ensure(int length)
    Ensure that the bytelist is at least length bytes long.
    boolean
    equal(ByteList other)
    Does this ByteList equal the other ByteList?
    boolean
    equals(Object other)
    Does this ByteList equal the other ByteList?
    void
    fill(int b, int len)
    Append the byte b up to len times onto the end of the current ByteList.
    int
    get(int index)
    Get the byte at index from the ByteList.
    int
     
    int
    getEnc(int index)
    Get the index code point in this ByteList.
    org.jcodings.Encoding
     
    int
     
    byte[]
     
    int
     
    int
    indexOf(int c)
    Get the index of first occurrence of c in ByteList from the beginning of the ByteList.
    int
    indexOf(int c, int pos)
    Get the index of first occurrence of c in ByteList from the pos offset of the ByteList.
    int
    Get the index of first occurrence of Bytelist find in this ByteList.
    int
    indexOf(ByteList find, int i)
    Get the index of first occurrence of Bytelist find in this ByteList starting at index i.
    void
    insert(int index, int b)
     
    void
    Invalidate the hash and stringValue which may have been cached in this ByteList.
    boolean
    Return true if the ByteList has zero length (byte length).
    int
    lastIndexOf(int c)
    Get the index of last occurrence of c in ByteList from the end of the ByteList.
    int
    lastIndexOf(int c, int pos)
    Get the index of last occurrence of c in ByteList from the pos offset of the ByteList.
    int
    Get the index of last occurrence of find in ByteList from the end of the ByteList.
    int
    lastIndexOf(ByteList find, int pos)
    Get the index of last occurrence of find in ByteList from the end of the ByteList.
    int
    Return the current length of the ByteList.
    void
    length(int newLength)
    Set the byte container length.
    int
    Number of characters in this ByteList based on its current encoding.
    makeShared(int index, int len)
    Make a shared copy of this ByteList.
    static int
    memcmp(byte[] first, int firstStart, byte[] second, int secondStart, int len)
    Are these two byte arrays similiar (semantics similiar to compareTo).
    static int
    memcmp(byte[] first, int firstStart, int firstLen, byte[] second, int secondStart, int secondLen)
    Are these two byte arrays similiar (semantics similiar to compareTo).
    static char[]
    plain(byte[] b)
    Create a char[] from a byte[] assuming a raw/ISO-8859-1 encoding
    static char[]
    plain(byte[] b, int start, int length)
    Create a char[] from a byte[] assuming a raw/ISO-8859-1 encoding
    static byte[]
    plain(char[] s)
    Create a byte[] from a char[] assuming a raw/ISO-8859-1 encoding
    static byte[]
    Create a byte[] from a CharSequence assuming a raw/ISO-8859-1 encoding
    void
    prepend(byte b)
    Prepend a byte onto the front of this ByteList.
    void
    realloc(int length)
    Resize the ByteList's backing store to be length in size.
    int
     
    void
    realSize(int realSize)
     
    void
    replace(byte[] source)
    Replace all bytes in this ByteList with bytes from the given array.
    void
    replace(int targetOff, int targetLen, byte[] source)
    Replace a region of bytes in this ByteList with bytes from the given array.
    void
    replace(int targetOff, int targetLen, byte[] source, int sourceOff, int sourceLen)
    Replace a region of bytes in this ByteList with a region of bytes from the given array.
    void
    replace(int targetOff, int targetLen, ByteList source)
    Replace a region of bytes in this ByteList with bytes from the given ByteList.
    static org.jcodings.Encoding
    safeEncoding(org.jcodings.Encoding incoming)
    Ensure the encoding is always non-null.
    boolean
    an alternative to the new version of equals, should detect inequality faster (in many cases), but is slow in the case of equal values (all bytes visited), due to using n+=2, n-=2 vs.
    void
    set(int index, int b)
    Set the byte at index to be new value.
    void
    setBegin(int begin)
     
    void
    setEncoding(org.jcodings.Encoding encoding)
     
    void
    setRealSize(int realSize)
     
    void
    setUnsafeBytes(byte[] bytes)
     
    Create a new ByteList but do not array copy the byte backing store.
    boolean
    Does this ByteList start with the supplied ByteList?
    boolean
    startsWith(ByteList other, int toffset)
     
    subSequence(int start, int end)
    Create subSequence of this array between start and end offsets
    Produce a String using the raw (ISO-8859-1) bytes of this ByteList.
    Remembers toString value, which is expensive for StringBuffer.
    byte[]
    Returns the internal byte array.
    void
    unsafeReplace(int beg, int len, byte[] buf)
    Unsafe version of replace(int,int,byte[]).
    void
    unsafeReplace(int beg, int len, byte[] nbytes, int index, int count)
    Unsafe version of replace(int,int,byte[],int,int).
    void
    unsafeReplace(int beg, int len, ByteList nbytes)
    Unsafe version of replace(int,int,ByteList).
    void
    Array copy the byte backing store so that you can guarantee that no other objects are referencing this objects backing store.
    void
    unshare(int length)
    Array copy the byte backing store so that you can guarantee that no other objects are referencing this objects backing store.
    void
    view(int index, int len)
    Change ByteBuffer to have a new begin that is +index positions past begin with a new length.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.CharSequence

    chars, codePoints
  • Field Details

    • NULL_ARRAY

      public static final byte[] NULL_ARRAY
    • EMPTY_BYTELIST

      public static final ByteList EMPTY_BYTELIST
    • bytes

      @Deprecated public byte[] bytes
      Deprecated.
    • begin

      @Deprecated public int begin
      Deprecated.
    • realSize

      @Deprecated public int realSize
      Deprecated.
  • Constructor Details

    • ByteList

      public ByteList()
      Creates a new instance of ByteList
    • ByteList

      public ByteList(int size)
      Creates a new instance of Bytelist with a pre-allocated size. If you know the size ahead of time this saves additional array allocations to grow the bytelist to the proper size.
      Parameters:
      size - to preallocate the bytelist to
    • ByteList

      public ByteList(int size, org.jcodings.Encoding enc)
      Creates a new instance of Bytelist with a pre-allocated size and specified encoding. See ByteList(int)
      Parameters:
      size - to preallocate the bytelist to
      enc - encoding to set
    • ByteList

      public ByteList(byte[] bytes, org.jcodings.Encoding encoding)
      Create a new instance of ByteList with the bytes supplied using the specified encoding. Important: bytes is used as the initial backing store for the bytelist. Over time as the bytelist is mutated this backing store may be replaced with a new one to hold the additional bytes. If you pass in bytes and then modify the contents of the original bytes, then those changes will get reflected.
      Parameters:
      bytes - to use
      encoding -
    • ByteList

      public ByteList(byte[] wrap)
      Create a new instance of ByteList with the contents of wrap. This constructor will make a copy of bytes passed
      Parameters:
      wrap - the initial bytes for this ByteList
    • ByteList

      public ByteList(byte[] wrap, boolean copy)
      Create a new instance of ByteList with the contents of wrap. If copy is true then it will array copy the contents. Otherwise it will use the byte array passed in as its initial backing store.
      Parameters:
      wrap - the initial bytes for this ByteList
      copy - whether to arraycopy wrap for the backing store or not
    • ByteList

      public ByteList(byte[] wrap, org.jcodings.Encoding encoding, boolean copy)
      Create a new instance of ByteList with the contents of wrap. If copy is true then it will array copy the contents. Otherwise it will use the byte array passed in as its initial backing store.
      Parameters:
      wrap - the initial bytes for this ByteList
      encoding - the encoding for the bytes
      copy - whether to arraycopy wrap for the backing store or not
    • ByteList

      public ByteList(ByteList wrap)
      Create a new instance of byte list with the same contents as the passed in ByteList wrap. Note that this does array copy the data for the new objects initial backing store.
      Parameters:
      wrap - is contents for new ByteList
    • ByteList

      public ByteList(byte[] wrap, int index, int len)
      Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is. wrap will be array copied in this constructor.
      Parameters:
      wrap - the bytes to use
      index - where in the bytes the data starts
      len - how long the data is in the wrap array
    • ByteList

      public ByteList(byte[] wrap, int index, int len, boolean copy)
      Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is. wrap will be array copied if copy is true OR if index != 0.
      Parameters:
      wrap - the bytes to use
      index - where in the bytes the data starts
      len - how long the data is in the wrap array
      copy - if true array copy wrap. otherwise use as backing store
    • ByteList

      public ByteList(byte[] wrap, int index, int len, org.jcodings.Encoding encoding, boolean copy)
      Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is. wrap will be array copied if copy is true OR if index != 0.
      Parameters:
      wrap - the bytes to use
      index - where in the bytes the data starts
      len - how long the data is in the wrap array
      copy - if true array copy wrap. otherwise use as backing store
    • ByteList

      public ByteList(ByteList wrap, int index, int len)
      Create a new instance of ByteList using wrap as a backing store where index is the first index in the byte array where the data starts and len indicates how long the data portion of the bytelist is. wrap's byte array will be array copied for initial backing store.
      Parameters:
      wrap - the bytes to use
      index - where in the bytes the data starts
      len - how long the data is in the wrap array
  • Method Details

    • delete

      public void delete(int start, int len)
      Delete len bytes from start index. This does no bullet-proofing so it is your responsibility to ensure you do not run off the backing store array.
      Parameters:
      start - index to delete from
      len - number of bytes to delete
    • fill

      public void fill(int b, int len)
      Append the byte b up to len times onto the end of the current ByteList.
      Parameters:
      b - is byte to be appended
      len - is number of times to repeat the append
    • clone

      public Object clone()
      Overrides:
      clone in class Object
      See Also:
    • dup

      public ByteList dup()
      creates a duplicate of this bytelist but only in the case of a stringValue and its resulting hash value. No other elements are duplicated.
    • shallowDup

      public ByteList shallowDup()
      Create a new ByteList but do not array copy the byte backing store.
      Returns:
      a new ByteList with same backing store
    • dup

      public ByteList dup(int length)
      Parameters:
      length - is the value of how big the buffer is going to be, not the actual length to copy It is used by RubyString.modify(int) to prevent COW pathological situations (namely to COW with having length - realSize bytes ahead)
    • ensure

      public void ensure(int length)
      Ensure that the bytelist is at least length bytes long. Otherwise grow the backing store so that it is at least length bytes long, but grow to 1.5 * length, if we're able to, to avoid thrashing.
      Parameters:
      length - to use to make sure ByteList is long enough
    • makeShared

      public ByteList makeShared(int index, int len)
      Make a shared copy of this ByteList. This is used for COW'ing ByteLists, you typically want a piece of the same backing store to be shared across ByteBuffers, while those ByteLists will be pointing at different indexes and lengths of the same backing store. Note: that this does not update hash or stringValue.
      Parameters:
      index - new begin value for shared ByteBuffer
      len - new length/realSize for chared
      Returns:
    • view

      public void view(int index, int len)
      Change ByteBuffer to have a new begin that is +index positions past begin with a new length.
      Parameters:
      index - new value to add to begin
      len - the new realSize/length value
    • unshare

      public void unshare()
      Array copy the byte backing store so that you can guarantee that no other objects are referencing this objects backing store.
    • unshare

      public void unshare(int length)
      Array copy the byte backing store so that you can guarantee that no other objects are referencing this objects backing store. This version on unshare allows a length to be specified which will copy length bytes from the old backing store.
      Parameters:
      length - is the value of how big the buffer is going to be, not the actual length to copy It is used by RubyString.modify(int) to prevent COW pathological situations (namely to COW with having length - realSize bytes ahead)
    • invalidate

      public void invalidate()
      Invalidate the hash and stringValue which may have been cached in this ByteList.
    • prepend

      public void prepend(byte b)
      Prepend a byte onto the front of this ByteList.
      Parameters:
      b - is the byte to be prepended
    • append

      public ByteList append(byte b)
      Append a single byte to the ByteList
      Parameters:
      b - the byte to be added
      Returns:
      this instance
    • append

      public ByteList append(int b)
      Append a single byte to the ByteList by truncating the given int
      Parameters:
      b - the int to truncated and added
      Returns:
      this instance
    • append

      public ByteList append(InputStream input, int len) throws IOException
      Append up to length bytes from InputStream to the ByteList. If no bytes are read from the stream then throw an IOException.
      Parameters:
      input - the stream to read bytes from
      len - how many bytes to try reading
      Returns:
      this instance
      Throws:
      IOException - when no bytes are read
    • append

      public void append(ByteBuffer buffer, int len)
      Append contents of the supplied nio ByteList up to len length onto the end of this ByteBuffer.
      Parameters:
      buffer - to be appended
      len - is number of bytes you hoping to get from the ByteBuffer
    • append

      public void append(byte[] moreBytes)
      Append moreBytes onto the end of the current ByteList.
      Parameters:
      moreBytes - to be added.
    • append

      public void append(ByteList moreBytes)
      Append moreBytes onto the end of the current ByteList.
      Parameters:
      moreBytes - to be added.
    • append

      public void append(ByteList moreBytes, int index, int len)
      Append moreBytes onto the end of the current ByteList with +index as the new begin for len bytes from the moreBytes ByteList.
      Parameters:
      moreBytes - to be added.
      index - new index past current begin value
      len - is the number of bytes to append from source ByteList
    • append

      public void append(byte[] moreBytes, int start, int len)
      Append moreBytes onto the end of the current ByteList with start as the new begin for len bytes from the moreBytes byte array.
      Parameters:
      moreBytes - to be added.
      start - is the new begin value
      len - is the number of bytes to append from source byte array
    • realloc

      public void realloc(int length)
      Resize the ByteList's backing store to be length in size. Note that this forces the backing store to array copy regardless of ByteLists current size or contents. It essentially will end any COWing.
      Parameters:
      length - the new length for the backing store.
    • length

      public int length()
      Return the current length of the ByteList.
      Specified by:
      length in interface CharSequence
      Returns:
      the number of bytes in this ByteList.
    • isEmpty

      public boolean isEmpty()
      Return true if the ByteList has zero length (byte length).
      Specified by:
      isEmpty in interface CharSequence
      Returns:
      true if empty, false otherwise
    • length

      public void length(int newLength)
      Set the byte container length.
      Parameters:
      newLength -
    • lengthEnc

      public int lengthEnc()
      Number of characters in this ByteList based on its current encoding.
      Returns:
      number of characters
    • get

      public int get(int index)
      Get the byte at index from the ByteList.
      Parameters:
      index - to retreive byte from
      Returns:
      the byte retreived
    • getEnc

      public int getEnc(int index)
      Get the index code point in this ByteList.
      Parameters:
      index - is the element you want
      Returns:
      the element you requested
    • set

      public void set(int index, int b)
      Set the byte at index to be new value.
      Parameters:
      index - to set byte
      b - is the new value.
    • unsafeReplace

      public void unsafeReplace(int beg, int len, ByteList nbytes)
      Unsafe version of replace(int,int,ByteList). The contract is that these unsafe versions will not make sure thet beg and len indices are correct.
    • unsafeReplace

      public void unsafeReplace(int beg, int len, byte[] buf)
      Unsafe version of replace(int,int,byte[]). The contract is that these unsafe versions will not make sure thet beg and len indices are correct.
    • unsafeReplace

      public void unsafeReplace(int beg, int len, byte[] nbytes, int index, int count)
      Unsafe version of replace(int,int,byte[],int,int). The contract is that these unsafe versions will not make sure thet beg and len indices are correct.
    • replace

      public void replace(byte[] source)
      Replace all bytes in this ByteList with bytes from the given array.
      Parameters:
      source - bytes to use for replacement
    • replace

      public void replace(int targetOff, int targetLen, ByteList source)
      Replace a region of bytes in this ByteList with bytes from the given ByteList.
      Parameters:
      targetOff - offset of target region in this ByteList
      targetLen - length of target region in this ByteList
      source - ByteList to use for replacement
    • replace

      public void replace(int targetOff, int targetLen, byte[] source)
      Replace a region of bytes in this ByteList with bytes from the given array.
      Parameters:
      targetOff - offset of target region in this ByteList
      targetLen - length of target region in this ByteList
      source - bytes to use for replacement
    • replace

      public void replace(int targetOff, int targetLen, byte[] source, int sourceOff, int sourceLen)
      Replace a region of bytes in this ByteList with a region of bytes from the given array.
      Parameters:
      targetOff - offset of target region in this ByteList
      targetLen - length of target region in this ByteList
      source - bytes to use for replacement
      sourceOff - offset of source region in the replacement bytes
      sourceLen - length of source region in the replacement bytes
    • insert

      public void insert(int index, int b)
    • indexOf

      public int indexOf(int c)
      Get the index of first occurrence of c in ByteList from the beginning of the ByteList.
      Parameters:
      c - byte to be looking for
      Returns:
      the index of the byte or -1 if not found
    • indexOf

      public int indexOf(int c, int pos)
      Get the index of first occurrence of c in ByteList from the pos offset of the ByteList.
      Parameters:
      c - byte to be looking for
      pos - off set from beginning of ByteList to look for byte
      Returns:
      the index of the byte or -1 if not found
    • indexOf

      public int indexOf(ByteList find)
      Get the index of first occurrence of Bytelist find in this ByteList.
      Parameters:
      find - the ByteList to find
      Returns:
      the index of the byte or -1 if not found
    • indexOf

      public int indexOf(ByteList find, int i)
      Get the index of first occurrence of Bytelist find in this ByteList starting at index i.
      Parameters:
      find - the ByteList to find
      i - the index to start from
      Returns:
      the index of the byte or -1 if not found
    • lastIndexOf

      public int lastIndexOf(int c)
      Get the index of last occurrence of c in ByteList from the end of the ByteList.
      Parameters:
      c - byte to be looking for
      Returns:
      the index of the byte or -1 if not found
    • lastIndexOf

      public int lastIndexOf(int c, int pos)
      Get the index of last occurrence of c in ByteList from the pos offset of the ByteList.
      Parameters:
      c - byte to be looking for
      pos - off set from end of ByteList to look for byte
      Returns:
      the index of the byte or -1 if not found
    • lastIndexOf

      public int lastIndexOf(ByteList find)
      Get the index of last occurrence of find in ByteList from the end of the ByteList.
      Parameters:
      find - ByteList to be looking for
      Returns:
      the index of the byte or -1 if not found
    • lastIndexOf

      public int lastIndexOf(ByteList find, int pos)
      Get the index of last occurrence of find in ByteList from the end of the ByteList.
      Parameters:
      find - ByteList to be looking for
      pos - index from end of list to search from
      Returns:
      the index of the byte or -1 if not found
    • startsWith

      public boolean startsWith(ByteList other, int toffset)
    • startsWith

      public boolean startsWith(ByteList other)
      Does this ByteList start with the supplied ByteList?
      Parameters:
      other - is the bytelist to compare with
      Returns:
      true is this ByteList starts with other
    • endsWith

      public boolean endsWith(ByteList other)
      Does this ByteList end with the supplied ByteList?
      Parameters:
      other - is the bytelist to compare with
      Returns:
      true is this ByteList starts with other
    • equals

      public boolean equals(Object other)
      Does this ByteList equal the other ByteList?
      Overrides:
      equals in class Object
      Parameters:
      other - is the bytelist to compare with
      Returns:
      true is this ByteList is the same
    • equal

      public boolean equal(ByteList other)
      Does this ByteList equal the other ByteList?
      Parameters:
      other - is the bytelist to compare with
      Returns:
      true is this ByteList is the same
    • sample_equals

      public boolean sample_equals(Object other)
      an alternative to the new version of equals, should detect inequality faster (in many cases), but is slow in the case of equal values (all bytes visited), due to using n+=2, n-=2 vs. ++n, --n while iterating over the array.
    • compareTo

      public int compareTo(Object other)
      This comparison matches MRI comparison of Strings (rb_str_cmp). I wish we had memcmp right now...
      Specified by:
      compareTo in interface Comparable
    • cmp

      public int cmp(ByteList other)
      This comparison matches MRI comparison of Strings (rb_str_cmp).
    • caseInsensitiveCmp

      public int caseInsensitiveCmp(ByteList other)
      Do a case insensitive comparison with other ByteList with return types similiar to compareTo.
      Parameters:
      other - the ByteList to compare
      Returns:
      -1, 0, or 1
    • unsafeBytes

      public byte[] unsafeBytes()
      Returns the internal byte array. This is unsafe unless you know what you're doing. But it can improve performance for byte-array operations that won't change the array.
      Returns:
      the internal byte array
    • bytes

      public byte[] bytes()
      Get a copy of the bytes referenced by this ByteList. It will make an optimal copy and not carry along unused bytes from COW sharing.
      Returns:
      a copy of the bytes.
    • begin

      public int begin()
      First index of the backing array that contains data for the ByteList. Note that we have copy-on-write (COW) semantics which means sharing the same backing store will yield different begin and size values while using the same byte[].
      Returns:
      the index
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
    • toString

      public String toString()
      Remembers toString value, which is expensive for StringBuffer.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
      Returns:
      an ISO-8859-1 representation of the byte list
    • toByteString

      public String toByteString()
      Produce a String using the raw (ISO-8859-1) bytes of this ByteList.
      Returns:
      a String based on the raw bytes
    • create

      public static ByteList create(CharSequence s)
      Create a bytelist with ISO_8859_1 encoding from the provided CharSequence.
      Parameters:
      s - the source for new ByteList
      Returns:
      the new ByteList
    • plain

      public static byte[] plain(CharSequence s)
      Create a byte[] from a CharSequence assuming a raw/ISO-8859-1 encoding
      Parameters:
      s - the CharSequence to convert
      Returns:
      a byte[]
    • plain

      public static byte[] plain(char[] s)
      Create a byte[] from a char[] assuming a raw/ISO-8859-1 encoding
      Parameters:
      s - the CharSequence to convert
      Returns:
      a byte[]
    • plain

      public static char[] plain(byte[] b, int start, int length)
      Create a char[] from a byte[] assuming a raw/ISO-8859-1 encoding
      Parameters:
      b - the source byte[]
      start - index to start converting to char's
      length - how many bytes to convert to char's
      Returns:
      a byte[]
    • plain

      public static char[] plain(byte[] b)
      Create a char[] from a byte[] assuming a raw/ISO-8859-1 encoding
      Parameters:
      b - the source byte[]
      Returns:
      a byte[]
    • decode

      public static String decode(byte[] data, int offset, int length, String charsetName)
      Decode byte data into a String with the supplied charsetName.
      Parameters:
      data - to be decoded
      offset - where to start decoding from in data
      length - how many bytes to decode from data
      charsetName - used to make the resulting String
      Returns:
      the new String
    • decode

      public static String decode(byte[] data, String charsetName)
      Decode byte data into a String with the supplied charsetName.
      Parameters:
      data - to be decoded
      charsetName - used to make the resulting String
      Returns:
      the new String
    • encode

      public static byte[] encode(CharSequence data, String charsetName)
      Encode CharSequence into a set of bytes based on the charsetName.
      Parameters:
      data - to be encoded
      charsetName - used to extract the resulting bytes
      Returns:
      the new byte[]
    • charAt

      public char charAt(int ix)
      Pretend byte array is raw and each byte is also the character value
      Specified by:
      charAt in interface CharSequence
      Parameters:
      ix - is the index you want
      Returns:
    • subSequence

      public CharSequence subSequence(int start, int end)
      Create subSequence of this array between start and end offsets
      Specified by:
      subSequence in interface CharSequence
      Parameters:
      start - index for beginning of subsequence
      end - index for end of subsequence
      Returns:
      a new ByteList/CharSequence
    • memcmp

      public static int memcmp(byte[] first, int firstStart, int firstLen, byte[] second, int secondStart, int secondLen)
      Are these two byte arrays similiar (semantics similiar to compareTo). This is slightly special in that it will only compare the same number of bytes based on the lesser of the two lengths.
      Returns:
      -1, 0, 1
    • memcmp

      public static int memcmp(byte[] first, int firstStart, byte[] second, int secondStart, int len)
      Are these two byte arrays similiar (semantics similiar to compareTo).
      Returns:
      -1, 0, 1
    • getUnsafeBytes

      public byte[] getUnsafeBytes()
      Returns:
      the bytes
    • setUnsafeBytes

      public void setUnsafeBytes(byte[] bytes)
      Parameters:
      bytes - the bytes to set
    • getBegin

      public int getBegin()
      Returns:
      the begin
    • setBegin

      public void setBegin(int begin)
      Parameters:
      begin - the begin to set
    • getRealSize

      public int getRealSize()
      Returns:
      the realSize
    • setRealSize

      public void setRealSize(int realSize)
      Parameters:
      realSize - the realSize to set
    • realSize

      public int realSize()
      Returns:
      the realSize
    • realSize

      public void realSize(int realSize)
      Parameters:
      realSize - the realSize to set
    • getEncoding

      public org.jcodings.Encoding getEncoding()
      Returns:
      the encoding
    • setEncoding

      public void setEncoding(org.jcodings.Encoding encoding)
      Parameters:
      encoding - the encoding to set
    • safeEncoding

      public static org.jcodings.Encoding safeEncoding(org.jcodings.Encoding incoming)
      Ensure the encoding is always non-null.