|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jruby.util.ByteList
public final class ByteList
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.
| 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 |
|---|
public static final byte[] NULL_ARRAY
public static final ByteList EMPTY_BYTELIST
@Deprecated public byte[] bytes
@Deprecated public int begin
@Deprecated public int realSize
@Deprecated public org.jcodings.Encoding encoding
| Constructor Detail |
|---|
public ByteList()
public ByteList(int size)
size - to preallocate the bytelist to
public ByteList(byte[] bytes,
org.jcodings.Encoding encoding)
bytes - to useencoding - public ByteList(byte[] wrap)
wrap - the initial bytes for this ByteList
public ByteList(byte[] wrap,
boolean copy)
wrap - the initial bytes for this ByteListcopy - whether to arraycopy wrap for the backing store or not
public ByteList(byte[] wrap,
org.jcodings.Encoding encoding,
boolean copy)
wrap - the initial bytes for this ByteListencoding - the encoding for the bytescopy - whether to arraycopy wrap for the backing store or notpublic ByteList(ByteList wrap)
wrap - is contents for new ByteList
@Deprecated
public ByteList(ByteList wrap,
boolean copy)
wrap - copy - Deprecated to coincide with JRuby 1.5 (not used by anything we can find luckily)
public ByteList(byte[] wrap,
int index,
int len)
wrap - the bytes to useindex - where in the bytes the data startslen - how long the data is in the wrap array
public ByteList(byte[] wrap,
int index,
int len,
boolean copy)
wrap - the bytes to useindex - where in the bytes the data startslen - how long the data is in the wrap arrayencoding - the encoding of the bytescopy - if true array copy wrap. otherwise use as backing store
public ByteList(byte[] wrap,
int index,
int len,
org.jcodings.Encoding encoding,
boolean copy)
wrap - the bytes to useindex - where in the bytes the data startslen - how long the data is in the wrap arraycopy - if true array copy wrap. otherwise use as backing store
public ByteList(ByteList wrap,
int index,
int len)
wrap - the bytes to useindex - where in the bytes the data startslen - how long the data is in the wrap array| Method Detail |
|---|
public void delete(int start,
int len)
start - index to delete fromlen - number of bytes to delete
public void fill(int b,
int len)
b - is byte to be appendedlen - is number of times to repeat the appendpublic Object clone()
clone in class ObjectObject.clone()public ByteList dup()
public ByteList shallowDup()
public ByteList dup(int length)
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)public void ensure(int length)
length - to use to make sure ByteList is long enough
public ByteList makeShared(int index,
int len)
index - new begin value for shared ByteBufferlen - new length/realSize for chared
public void view(int index,
int len)
index - new value to add to beginlen - the new realSize/length valuepublic void unshare()
public void unshare(int length)
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)public void invalidate()
public void prepend(byte b)
b - is the byte to be prependedpublic ByteList append(byte b)
b - the byte to be added
public ByteList append(int b)
b - the int to be added
public ByteList append(InputStream input,
int length)
throws IOException
input - the stream to read bytes fromlength - how many byte to try and read
IOException - when no bytes are read
public void append(ByteBuffer buffer,
int len)
buffer - to be appendedlen - is number of bytes you hoping to get from the ByteBufferpublic void append(byte[] moreBytes)
moreBytes - to be added.public void append(ByteList moreBytes)
moreBytes - to be added.
public void append(ByteList moreBytes,
int index,
int len)
moreBytes - to be added.index - new index past current begin valuelen - is the number of bytes to append from source ByteList
public void append(byte[] moreBytes,
int start,
int len)
moreBytes - to be added.start - is the new begin valuelen - is the number of bytes to append from source byte arraypublic void realloc(int length)
length - the new length for the backing store.public int length()
length in interface CharSequencepublic void length(int newLength)
newLength - public int lengthEnc()
public int get(int index)
index - to retreive byte from
public int getEnc(int index)
index - is the element you want
public void set(int index,
int b)
index - to set byteb - is the new value.@Deprecated public void replace(byte[] newBytes)
newBytes -
public void unsafeReplace(int beg,
int len,
ByteList nbytes)
public void unsafeReplace(int beg,
int len,
byte[] buf)
public void unsafeReplace(int beg,
int len,
byte[] nbytes,
int index,
int count)
public void replace(int beg,
int len,
ByteList nbytes)
beg - len - nbytes -
public void replace(int beg,
int len,
byte[] buf)
beg - len - buf -
public void replace(int beg,
int len,
byte[] nbytes,
int index,
int count)
beg - len - nbytes - index - count -
public void insert(int index,
int b)
public int indexOf(int c)
c - byte to be looking for
public int indexOf(int c,
int pos)
c - byte to be looking forpos - off set from beginning of ByteList to look for byte
public int indexOf(ByteList find)
find - the ByteList to find
public int indexOf(ByteList find,
int i)
find - the ByteList to findi - the index to start from
public int lastIndexOf(int c)
c - byte to be looking for
public int lastIndexOf(int c,
int pos)
c - byte to be looking forpos - off set from end of ByteList to look for byte
public int lastIndexOf(ByteList find)
find - ByteList to be looking for
public int lastIndexOf(ByteList find,
int pos)
find - ByteList to be looking forpos - index from end of list to search from
public boolean startsWith(ByteList other,
int toffset)
public boolean startsWith(ByteList other)
other - is the bytelist to compare with
public boolean endsWith(ByteList other)
other - is the bytelist to compare with
public boolean equals(Object other)
equals in class Objectother - is the bytelist to compare with
public boolean equal(ByteList other)
other - is the bytelist to compare with
public boolean sample_equals(Object other)
public int compareTo(Object other)
compareTo in interface Comparablepublic int cmp(ByteList other)
public int caseInsensitiveCmp(ByteList other)
other - the ByteList to compare
public byte[] unsafeBytes()
public byte[] bytes()
public int begin()
public int hashCode()
hashCode in class ObjectObject.hashCode()public String toString()
toString in interface CharSequencetoString in class Objectpublic static ByteList create(CharSequence s)
s - the source for new ByteList
public static byte[] plain(CharSequence s)
s - the CharSequence to convert
public static byte[] plain(char[] s)
s - the CharSequence to convert
public static char[] plain(byte[] b,
int start,
int length)
b - the source byte[]start - index to start converting to char'slength - how many bytes to convert to char's
public static char[] plain(byte[] b)
b - the source byte[]
public static String decode(byte[] data,
int offset,
int length,
String charsetName)
data - to be decodedoffset - where to start decoding from in datalength - how many bytes to decode from datacharsetName - used to make the resulting String
public static String decode(byte[] data,
String charsetName)
data - to be decodedcharsetName - used to make the resulting String
public static byte[] encode(CharSequence data,
String charsetName)
data - to be encodedcharsetName - used to extract the resulting bytes
public char charAt(int ix)
charAt in interface CharSequenceix - is the index you want
public CharSequence subSequence(int start,
int end)
subSequence in interface CharSequencestart - index for beginning of subsequenceend - index for end of subsequence
public static int memcmp(byte[] first,
int firstStart,
int firstLen,
byte[] second,
int secondStart,
int secondLen)
public static int memcmp(byte[] first,
int firstStart,
byte[] second,
int secondStart,
int len)
public final byte[] getUnsafeBytes()
public final void setUnsafeBytes(byte[] bytes)
bytes - the bytes to setpublic final int getBegin()
public final void setBegin(int begin)
begin - the begin to setpublic final int getRealSize()
public final void setRealSize(int realSize)
realSize - the realSize to setpublic final org.jcodings.Encoding getEncoding()
public final void setEncoding(org.jcodings.Encoding encoding)
encoding - the encoding to setpublic static org.jcodings.Encoding safeEncoding(org.jcodings.Encoding incoming)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||