com.jkristian.lang
Interface ByteSequence

All Known Implementing Classes:
ByteArrayBuffer, ByteArraySequence

public interface ByteSequence

A readable sequence of bytes. This is like a CharSequence, except the elements are bytes instead of chars.

This interface does not refine the general contracts of the equals and hashCode methods. But implementors are strongly encouraged to re-use ByteSequenceHelper.equals and hashCode, thereby making it possible to compare ByteSequences and use immutable ByteSequences as Map keys.

Author:
John Kristian

Method Summary
 byte byteAt(int index)
           
 void copy(int start, int end, byte[] into)
          Copy a sub-sequence into a given array.
 void copy(int start, int end, byte[] into, int intoStart)
          Copy a sub-sequence into a given array.
 int length()
           
 ByteSequence subSequence(int start, int end)
          Create a read-only view of this sequence.
 byte[] toByteArray()
          Copy this sequence into a new array.
 byte[] toByteArray(int start, int end)
          Copy a sub-sequence into a new array.
 java.lang.String toString(int start, int end, java.lang.String encoding)
          new String(toByteArray(start, end), encoding)
 java.lang.String toString(java.lang.String encoding)
          toString(0, length(), encoding)
 void writeTo(int start, int end, java.io.OutputStream out)
          Copy a sub-sequence into an OutputStream.
 void writeTo(java.io.OutputStream out)
          Copy this sequence into an OutputStream.
 

Method Detail

length

int length()

byteAt

byte byteAt(int index)

toByteArray

byte[] toByteArray()
Copy this sequence into a new array. Equivalent to toByteArray(0, length()).


toByteArray

byte[] toByteArray(int start,
                   int end)
Copy a sub-sequence into a new array.


copy

void copy(int start,
          int end,
          byte[] into)
Copy a sub-sequence into a given array. Equivalent to copy(start, end, into, 0).


copy

void copy(int start,
          int end,
          byte[] into,
          int intoStart)
Copy a sub-sequence into a given array.


toString

java.lang.String toString(java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException
toString(0, length(), encoding)

Throws:
java.io.UnsupportedEncodingException

toString

java.lang.String toString(int start,
                          int end,
                          java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException
new String(toByteArray(start, end), encoding)

Throws:
java.io.UnsupportedEncodingException

writeTo

void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Copy this sequence into an OutputStream. Equivalent to writeTo(0, length(), out).

Throws:
java.io.IOException

writeTo

void writeTo(int start,
             int end,
             java.io.OutputStream out)
             throws java.io.IOException
Copy a sub-sequence into an OutputStream.

Throws:
java.io.IOException

subSequence

ByteSequence subSequence(int start,
                         int end)
Create a read-only view of this sequence.

The returned sequence shares this sequence's content; that is, any changes to the bytes in the given range of this sequence will be visible in the sub-sequence.