public class ByteList
extends java.lang.Object
implements java.lang.Comparable, java.lang.CharSequence, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
int |
begin
Deprecated.
|
byte[] |
bytes
Deprecated.
|
static ByteList |
EMPTY_BYTELIST |
static byte[] |
NULL_ARRAY |
int |
realSize
Deprecated.
|
Constructor and Description |
---|
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,
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.
|
Modifier and Type | Method and Description |
---|---|
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(java.nio.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(java.io.InputStream input,
int len)
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
|
java.lang.Object |
clone() |
int |
cmp(ByteList other)
This comparison matches MRI comparison of Strings (rb_str_cmp).
|
int |
compareTo(java.lang.Object other)
This comparison matches MRI comparison of Strings (rb_str_cmp).
|
static ByteList |
create(java.lang.CharSequence s)
Create a bytelist with ISO_8859_1 encoding from the provided CharSequence.
|
static java.lang.String |
decode(byte[] data,
int offset,
int length,
java.lang.String charsetName)
Decode byte data into a String with the supplied charsetName.
|
static java.lang.String |
decode(byte[] data,
java.lang.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(java.lang.CharSequence data,
java.lang.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(java.lang.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.
|
boolean |
isEmpty()
Return true if the ByteList has zero length (byte length).
|
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)
Set the byte container length.
|
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 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[] |
plain(java.lang.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.
|
int |
realSize() |
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 |
sample_equals(java.lang.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) |
java.lang.CharSequence |
subSequence(int start,
int end)
Create subSequence of this array between start and end offsets
|
java.lang.String |
toByteString()
Produce a String using the raw (ISO-8859-1) bytes of this ByteList.
|
java.lang.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.
|
public static final byte[] NULL_ARRAY
public static final ByteList EMPTY_BYTELIST
@Deprecated public byte[] bytes
@Deprecated public int begin
@Deprecated public int realSize
public ByteList()
public ByteList(int size)
size
- to preallocate the bytelist topublic ByteList(byte[] bytes, org.jcodings.Encoding encoding)
bytes
- to useencoding
- public ByteList(byte[] wrap)
wrap
- the initial bytes for this ByteListpublic ByteList(byte[] wrap, boolean copy)
wrap
- the initial bytes for this ByteListcopy
- whether to arraycopy wrap for the backing store or notpublic 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 ByteListpublic 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 arraypublic 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 arraycopy
- if true array copy wrap. otherwise use as backing storepublic 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 storepublic 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 arraypublic void delete(int start, int len)
start
- index to delete fromlen
- number of bytes to deletepublic void fill(int b, int len)
b
- is byte to be appendedlen
- is number of times to repeat the appendpublic java.lang.Object clone()
clone
in class java.lang.Object
Object.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 enoughpublic ByteList makeShared(int index, int len)
index
- new begin value for shared ByteBufferlen
- new length/realSize for charedpublic 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 addedpublic ByteList append(int b)
b
- the int to be addedpublic ByteList append(java.io.InputStream input, int len) throws java.io.IOException
input
- the stream to read bytes fromlen
- how many bytes to try readingjava.io.IOException
- when no bytes are readpublic void append(java.nio.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 ByteListpublic 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 java.lang.CharSequence
public boolean isEmpty()
public void length(int newLength)
newLength
- public int lengthEnc()
public int get(int index)
index
- to retreive byte frompublic int getEnc(int index)
index
- is the element you wantpublic void set(int index, int b)
index
- to set byteb
- is the new value.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(byte[] source)
source
- bytes to use for replacementpublic void replace(int targetOff, int targetLen, ByteList source)
targetOff
- offset of target region in this ByteListtargetLen
- length of target region in this ByteListsource
- ByteList to use for replacementpublic void replace(int targetOff, int targetLen, byte[] source)
targetOff
- offset of target region in this ByteListtargetLen
- length of target region in this ByteListsource
- bytes to use for replacementpublic void replace(int targetOff, int targetLen, byte[] source, int sourceOff, int sourceLen)
targetOff
- offset of target region in this ByteListtargetLen
- length of target region in this ByteListsource
- bytes to use for replacementsourceOff
- offset of source region in the replacement bytessourceLen
- length of source region in the replacement bytespublic void insert(int index, int b)
public int indexOf(int c)
c
- byte to be looking forpublic int indexOf(int c, int pos)
c
- byte to be looking forpos
- off set from beginning of ByteList to look for bytepublic int indexOf(ByteList find)
find
- the ByteList to findpublic int indexOf(ByteList find, int i)
find
- the ByteList to findi
- the index to start frompublic int lastIndexOf(int c)
c
- byte to be looking forpublic int lastIndexOf(int c, int pos)
c
- byte to be looking forpos
- off set from end of ByteList to look for bytepublic int lastIndexOf(ByteList find)
find
- ByteList to be looking forpublic int lastIndexOf(ByteList find, int pos)
find
- ByteList to be looking forpos
- index from end of list to search frompublic boolean startsWith(ByteList other, int toffset)
public boolean startsWith(ByteList other)
other
- is the bytelist to compare withpublic boolean endsWith(ByteList other)
other
- is the bytelist to compare withpublic boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- is the bytelist to compare withpublic boolean equal(ByteList other)
other
- is the bytelist to compare withpublic boolean sample_equals(java.lang.Object other)
public int compareTo(java.lang.Object other)
compareTo
in interface java.lang.Comparable
public int cmp(ByteList other)
public int caseInsensitiveCmp(ByteList other)
other
- the ByteList to comparepublic byte[] unsafeBytes()
public byte[] bytes()
public int begin()
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public java.lang.String toByteString()
public static ByteList create(java.lang.CharSequence s)
s
- the source for new ByteListpublic static byte[] plain(java.lang.CharSequence s)
s
- the CharSequence to convertpublic static byte[] plain(char[] s)
s
- the CharSequence to convertpublic 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'spublic static char[] plain(byte[] b)
b
- the source byte[]public static java.lang.String decode(byte[] data, int offset, int length, java.lang.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 Stringpublic static java.lang.String decode(byte[] data, java.lang.String charsetName)
data
- to be decodedcharsetName
- used to make the resulting Stringpublic static byte[] encode(java.lang.CharSequence data, java.lang.String charsetName)
data
- to be encodedcharsetName
- used to extract the resulting bytespublic char charAt(int ix)
charAt
in interface java.lang.CharSequence
ix
- is the index you wantpublic java.lang.CharSequence subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
start
- index for beginning of subsequenceend
- index for end of subsequencepublic 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 byte[] getUnsafeBytes()
public void setUnsafeBytes(byte[] bytes)
bytes
- the bytes to setpublic int getBegin()
public void setBegin(int begin)
begin
- the begin to setpublic int getRealSize()
public void setRealSize(int realSize)
realSize
- the realSize to setpublic int realSize()
public void realSize(int realSize)
realSize
- the realSize to setpublic org.jcodings.Encoding getEncoding()
public void setEncoding(org.jcodings.Encoding encoding)
encoding
- the encoding to setpublic static org.jcodings.Encoding safeEncoding(org.jcodings.Encoding incoming)
Copyright © 2001-2020 JRuby. All Rights Reserved.