org.jruby.util
Class ByteList

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

public final 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, it's API resembles StringBuffer/StringBuilder more than String because it is a mutable object.

See Also:
Serialized Form

Field Summary
 int begin
          Deprecated. 
 byte[] bytes
          Deprecated. 
static ByteList EMPTY_BYTELIST
           
 org.jcodings.Encoding encoding
          Deprecated. 
static byte[] NULL_ARRAY
           
 int realSize
          Deprecated. 
 
Constructor Summary
ByteList()
          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[] 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(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(ByteList wrap)
          Create a new instance of byte list with the same contents as the passed in ByteList wrap.
ByteList(ByteList wrap, boolean copy)
          Deprecated. 
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.
ByteList(int size)
          Creates a new instance of Bytelist with a pre-allocated size.
 
Method Summary
 ByteList 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.
 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.
 ByteList append(InputStream input, int length)
          Append up to length bytes from InputStream to the ByteList.
 ByteList append(int b)
          Append a single int to the ByteList
 int begin()
          First index of the backing array that contains data for the ByteList.
 byte[] bytes()
          Get a copy of the bytes referenced by this ByteList.
 int caseInsensitiveCmp(ByteList other)
          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
 Object clone()
           
 int cmp(ByteList other)
          This comparison matches MRI comparison of Strings (rb_str_cmp).
 int compareTo(Object other)
          This comparison matches MRI comparison of Strings (rb_str_cmp).
static ByteList create(CharSequence s)
          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.
 ByteList dup()
          creates a duplicate of this bytelist but only in the case of a stringValue and its resulting hash value.
 ByteList dup(int length)
           
static byte[] encode(CharSequence data, String charsetName)
          Encode CharSequence into a set of bytes based on the charsetName.
 boolean endsWith(ByteList other)
          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 getBegin()
           
 int getEnc(int index)
          Get the index code point in this ByteList.
 org.jcodings.Encoding getEncoding()
           
 int getRealSize()
           
 byte[] getUnsafeBytes()
           
 int hashCode()
           
 int indexOf(ByteList find)
          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.
 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.
 void insert(int index, int b)
           
 void invalidate()
          Invalidate the hash and stringValue which may have been cached in this ByteList.
 int lastIndexOf(ByteList find)
          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 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 length()
          Return the current length of the ByteList.
 void length(int newLength)
          grow the bytelist to be newLength in size.
 int lengthEnc()
          Number of characters in this ByteList based on its current encoding.
 ByteList 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 too compareTo).
static int memcmp(byte[] first, int firstStart, int firstLen, byte[] second, int secondStart, int secondLen)
          Are these two byte arrays similiar (semantics similiar too 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[] plain(CharSequence s)
          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.
 void replace(byte[] newBytes)
          Deprecated. 
 void replace(int beg, int len, byte[] buf)
          Note: This is as unsafe as unsafeReplace
 void replace(int beg, int len, byte[] nbytes, int index, int count)
          Note: This is as unsafe as unsafeReplace
 void replace(int beg, int len, ByteList nbytes)
          Note: This is as unsafe as unsafeReplace
static org.jcodings.Encoding safeEncoding(org.jcodings.Encoding incoming)
          Ensure the encoding is always non-null.
 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.
 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)
           
 ByteList shallowDup()
          Create a new ByteList but do not array copy the byte backing store.
 boolean startsWith(ByteList other)
          Does this ByteList start with the supplied ByteList?
 boolean startsWith(ByteList other, int toffset)
           
 CharSequence subSequence(int start, int end)
          Create subSequence of this array between start and end offsets
 String toString()
          Remembers toString value, which is expensive for StringBuffer.
 byte[] unsafeBytes()
          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 unshare()
          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
 

Field Detail

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. 

encoding

@Deprecated
public org.jcodings.Encoding encoding
Deprecated. 
Constructor Detail

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(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

@Deprecated
public ByteList(ByteList wrap,
                           boolean copy)
Deprecated. 

Create a new instance of ByteList with the same contents as the passed in ByteList wrap. The copy parameter gives you control over whether you want this new ByteList to share the same byte array for its backing store. ****IMPORTANT NOTES***** copy is currently ignored and always assumed false. This constructor should just go away so it has been marked as deprecated.

Parameters:
wrap -
copy - Deprecated to coincide with JRuby 1.5 (not used by anything we can find luckily)

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
encoding - the encoding of the bytes
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 Detail

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:
Object.clone()

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 length bytes long

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 int to the ByteList

Parameters:
b - the int to be added
Returns:
this instance

append

public ByteList append(InputStream input,
                       int length)
                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
length - how many byte to try and read
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.

length

public void length(int newLength)
grow the bytelist to be newLength in size.

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.

replace

@Deprecated
public void replace(byte[] newBytes)
Deprecated. 

Replace the byte array backing store with newBytes. This method is only referred to in deprecated method RubyString.view(CharSequence). We deprecated this method because it ignore begin and if we

Parameters:
newBytes -

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(int beg,
                    int len,
                    ByteList nbytes)
Note: This is as unsafe as unsafeReplace

Parameters:
beg -
len -
nbytes -

replace

public void replace(int beg,
                    int len,
                    byte[] buf)
Note: This is as unsafe as unsafeReplace

Parameters:
beg -
len -
buf -

replace

public void replace(int beg,
                    int len,
                    byte[] nbytes,
                    int index,
                    int count)
Note: This is as unsafe as unsafeReplace

Parameters:
beg -
len -
nbytes -
index -
count -

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:
Object.hashCode()

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

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 too 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 too compareTo).

Returns:
-1, 0, 1

getUnsafeBytes

public final byte[] getUnsafeBytes()
Returns:
the bytes

setUnsafeBytes

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

getBegin

public final int getBegin()
Returns:
the begin

setBegin

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

getRealSize

public final int getRealSize()
Returns:
the realSize

setRealSize

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

getEncoding

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

setEncoding

public final 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.



Copyright © 2011. All Rights Reserved.