Top Description Fields Constructors Methods
org.jruby.util

public Class ByteList

extends Object
implements Comparable, CharSequence, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.CharSequence, java.lang.Comparable
Annotations
@SuppressWarnings:ComparableType
Imports
java.io.IOException, .InputStream, .Serializable, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .StandardCharsets, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, org.jcodings.Encoding, org.jcodings.ascii.AsciiTables, org.jcodings.specific.ASCIIEncoding, org.jruby.RubyEncoding, org.jruby.runtime.Helpers

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.

Field Summary

Modifier and TypeField and Description
public int
begin

Deprecated
public byte[]
bytes

Deprecated
private static final ConcurrentMap<String, Charset>
private static final int
public static final ByteList
private Encoding
pack-priv transient int
private static final Charset
public static final byte[]
public int
realSize

Deprecated
private static final long
pack-priv transient String

Constructor Summary

AccessConstructor and Description
public
ByteList()

Creates a new instance of ByteList

public
ByteList(int
to preallocate the bytelist to
size
)

Creates a new instance of Bytelist with a pre-allocated size.

public
ByteList(int
to preallocate the bytelist to
size
,
Encoding
encoding to set
enc
)

Creates a new instance of Bytelist with a pre-allocated size and specified encoding.

public
ByteList(byte[]
to use
bytes
,
Encoding encoding)

Create a new instance of ByteList with the bytes supplied using the specified encoding.

public
ByteList(byte[]
the initial bytes for this ByteList
wrap
)

Create a new instance of ByteList with the contents of wrap.

public
ByteList(byte[]
the initial bytes for this ByteList
wrap
,
boolean
whether to arraycopy wrap for the backing store or not
copy
)

Create a new instance of ByteList with the contents of wrap.

public
ByteList(byte[]
the initial bytes for this ByteList
wrap
,
Encoding
the encoding for the bytes
encoding
,
boolean
whether to arraycopy wrap for the backing store or not
copy
)

Create a new instance of ByteList with the contents of wrap.

public
ByteList(ByteList
is contents for new ByteList
wrap
)

Create a new instance of byte list with the same contents as the passed in ByteList wrap.

public
ByteList(byte[]
the bytes to use
wrap
,
int
where in the bytes the data starts
index
,
int
how long the data is in the wrap array
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.

public
ByteList(byte[]
the bytes to use
wrap
,
int
where in the bytes the data starts
index
,
int
how long the data is in the wrap array
len
,
boolean
if true array copy wrap. otherwise use as backing store
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.

public
ByteList(byte[]
the bytes to use
wrap
,
int
where in the bytes the data starts
index
,
int
how long the data is in the wrap array
len
,
Encoding encoding, boolean
if true array copy wrap. otherwise use as backing store
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.

public
ByteList(ByteList
the bytes to use
wrap
,
int
where in the bytes the data starts
index
,
int
how long the data is in the wrap array
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 TypeMethod and Description
public ByteList

Returns:

this instance
append
(byte
the byte to be added
b
)

Append a single byte to the ByteList

public ByteList

Returns:

this instance
append
(int
the int to truncated and added
b
)

Append a single byte to the ByteList by truncating the given int

public ByteList

Returns:

this instance
append
(InputStream
the stream to read bytes from
input
,
int
how many bytes to try reading
len
)

Append up to length bytes from InputStream to the ByteList.

public void
append(ByteBuffer
to be appended
buffer
,
int
is number of bytes you hoping to get from the ByteBuffer
len
)

Append contents of the supplied nio ByteList up to len length onto the end of this ByteBuffer.

public void
append(byte[]
to be added.
moreBytes
)

Append moreBytes onto the end of the current ByteList.

public void
append(ByteList
to be added.
moreBytes
)

Append moreBytes onto the end of the current ByteList.

public void
append(ByteList
to be added.
moreBytes
,
int
new index past current begin value
index
,
int
is the number of bytes to append from source ByteList
len
)

Append moreBytes onto the end of the current ByteList with +index as the new begin for len bytes from the moreBytes ByteList.

public void
append(byte[]
to be added.
moreBytes
,
int
is the new begin value
start
,
int
is the number of bytes to append from source byte array
len
)

Append moreBytes onto the end of the current ByteList with start as the new begin for len bytes from the moreBytes byte array.

public int

Returns:

the index
begin
()

First index of the backing array that contains data for the ByteList.

public byte[]

Returns:

a copy of the bytes.
bytes
()

Get a copy of the bytes referenced by this ByteList.

public int

Returns:

-1, 0, or 1
caseInsensitiveCmp
(final ByteList
the ByteList to compare
other
)

Do a case insensitive comparison with other ByteList with return types similiar to compareTo.

public char
charAt(int
is the index you want
ix
)

Implements java.lang.CharSequence.charAt.

Pretend byte array is raw and each byte is also the character value

public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public int
cmp(final ByteList other)

This comparison matches MRI comparison of Strings (rb_str_cmp).

public int
compareTo(Object
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

This comparison matches MRI comparison of Strings (rb_str_cmp).

public static ByteList

Returns:

the new ByteList
create
(CharSequence
the source for new ByteList
s
)

Create a bytelist with ISO_8859_1 encoding from the provided CharSequence.

public static String

Returns:

the new String
decode
(byte[]
to be decoded
data
,
int
where to start decoding from in data
offset
,
int
how many bytes to decode from data
length
,
String
used to make the resulting String
charsetName
)

Decode byte data into a String with the supplied charsetName.

private static String
decode(byte[] data, int offset, int length, Charset charset)

public static String

Returns:

the new String
decode
(byte[]
to be decoded
data
,
String
used to make the resulting String
charsetName
)

Decode byte data into a String with the supplied charsetName.

public void
delete(int
index to delete from
start
,
int
number of bytes to delete
len
)

Delete len bytes from start index.

public ByteList
dup()

creates a duplicate of this bytelist but only in the case of a stringValue and its resulting hash value.

public ByteList
dup(int
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)
length
)

public static byte[]

Returns:

the new byte[]
encode
(CharSequence
to be encoded
data
,
String
used to extract the resulting bytes
charsetName
)

Encode CharSequence into a set of bytes based on the charsetName.

public boolean

Returns:

true is this ByteList starts with other
endsWith
(ByteList
is the bytelist to compare with
other
)

Does this ByteList end with the supplied ByteList?

public void
ensure(int
to use to make sure ByteList is long enough
length
)

Ensure that the bytelist is at least length bytes long.

public boolean

Returns:

true is this ByteList is the same
equal
(ByteList
is the bytelist to compare with
other
)

Does this ByteList equal the other ByteList?

public boolean

Returns:

true is this ByteList is the same
equals
(Object
is the bytelist to compare with
other
)

Overrides java.lang.Object.equals.

Does this ByteList equal the other ByteList?

public void
fill(final int
is byte to be appended
b
,
final int
is number of times to repeat the append
len
)

Append the byte b up to len times onto the end of the current ByteList.

public int

Returns:

the byte retreived
get
(int
to retreive byte from
index
)

Get the byte at index from the ByteList.

public int

Returns:

the begin
getBegin
()

public int

Returns:

the element you requested
getEnc
(int
is the element you want
index
)

Get the index code point in this ByteList.

public Encoding

Returns:

the encoding
getEncoding
()

public int

Returns:

the realSize
getRealSize
()

public byte[]

Returns:

the bytes
getUnsafeBytes
()

private void
grow(int
number of bytes to grow
increaseRequested
)

Grow the ByteList by increaseRequested bytes.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int

Returns:

the index of the byte or -1 if not found
indexOf
(int
byte to be looking for
c
)

Get the index of first occurrence of c in ByteList from the beginning of the ByteList.

public int

Returns:

the index of the byte or -1 if not found
indexOf
(final int
byte to be looking for
c
,
int
off set from beginning of ByteList to look for byte
pos
)

Get the index of first occurrence of c in ByteList from the pos offset of the ByteList.

public int

Returns:

the index of the byte or -1 if not found
indexOf
(ByteList
the ByteList to find
find
)

Get the index of first occurrence of Bytelist find in this ByteList.

public int

Returns:

the index of the byte or -1 if not found
indexOf
(ByteList
the ByteList to find
find
,
int
the index to start from
i
)

Get the index of first occurrence of Bytelist find in this ByteList starting at index i.

pack-priv static int

Returns:

the index of the byte or -1 if not found
indexOf
(byte[] source, int sourceOffset, int sourceCount, byte[] target, int targetOffset, int targetCount, int fromIndex)

Get the index of first occurrence of target in source using the offset and count parameters.

public void
insert(int index, int b)

public void
invalidate()

Invalidate the hash and stringValue which may have been cached in this ByteList.

public boolean

Returns:

true if empty, false otherwise
isEmpty
()

Overrides default java.lang.CharSequence.isEmpty.

Return true if the ByteList has zero length (byte length).

public int

Returns:

the index of the byte or -1 if not found
lastIndexOf
(int
byte to be looking for
c
)

Get the index of last occurrence of c in ByteList from the end of the ByteList.

public int

Returns:

the index of the byte or -1 if not found
lastIndexOf
(final int
byte to be looking for
c
,
int
off set from end of ByteList to look for byte
pos
)

Get the index of last occurrence of c in ByteList from the pos offset of the ByteList.

public int

Returns:

the index of the byte or -1 if not found
lastIndexOf
(ByteList
ByteList to be looking for
find
)

Get the index of last occurrence of find in ByteList from the end of the ByteList.

public int

Returns:

the index of the byte or -1 if not found
lastIndexOf
(ByteList
ByteList to be looking for
find
,
int
index from end of list to search from
pos
)

Get the index of last occurrence of find in ByteList from the end of the ByteList.

pack-priv static int

Returns:

the index of the byte or -1 if not found
lastIndexOf
(byte[] source, int sourceOffset, int sourceCount, byte[] target, int targetOffset, int targetCount, int fromIndex)

Get the index of last occurrence of target in source using the offset and count parameters.

public int

Returns:

the number of bytes in this ByteList.
length
()

Implements java.lang.CharSequence.length.

Return the current length of the ByteList.

public void
length(int newLength)

Set the byte container length.

public int

Returns:

number of characters
lengthEnc
()

Number of characters in this ByteList based on its current encoding.

private static Charset
lookup(String alias)

public ByteList
makeShared(int
new begin value for shared ByteBuffer
index
,
int
new length/realSize for chared
len
)

Make a shared copy of this ByteList.

public static int

Returns:

-1, 0, 1
memcmp
(final byte[] first, final int firstStart, final int firstLen, final byte[] second, final int secondStart, final int secondLen)

Are these two byte arrays similiar (semantics similiar to compareTo).

public static int

Returns:

-1, 0, 1
memcmp
(final byte[] first, final int firstStart, final byte[] second, final int secondStart, int len)

Are these two byte arrays similiar (semantics similiar to compareTo).

public static byte[]

Returns:

a byte[]
plain
(CharSequence
the CharSequence to convert
s
)

Create a byte[] from a CharSequence assuming a raw/ISO-8859-1 encoding

public static byte[]

Returns:

a byte[]
plain
(char[]
the CharSequence to convert
s
)

Create a byte[] from a char[] assuming a raw/ISO-8859-1 encoding

public static char[]

Returns:

a byte[]
plain
(byte[]
the source byte[]
b
,
int
index to start converting to char's
start
,
int
how many bytes to convert to char's
length
)

Create a char[] from a byte[] assuming a raw/ISO-8859-1 encoding

public static char[]

Returns:

a byte[]
plain
(byte[]
the source byte[]
b
)

Create a char[] from a byte[] assuming a raw/ISO-8859-1 encoding

public void
prepend(byte
is the byte to be prepended
b
)

Prepend a byte onto the front of this ByteList.

public void
realloc(int
the new length for the backing store.
length
)

Resize the ByteList's backing store to be length in size.

public int

Returns:

the realSize
realSize
()

public void
realSize(int
the realSize to set
realSize
)

public void
replace(byte[]
bytes to use for replacement
source
)

Replace all bytes in this ByteList with bytes from the given array.

public void
replace(int
offset of target region in this ByteList
targetOff
,
int
length of target region in this ByteList
targetLen
,
ByteList
ByteList to use for replacement
source
)

Replace a region of bytes in this ByteList with bytes from the given ByteList.

public void
replace(int
offset of target region in this ByteList
targetOff
,
int
length of target region in this ByteList
targetLen
,
byte[]
bytes to use for replacement
source
)

Replace a region of bytes in this ByteList with bytes from the given array.

public void
replace(int
offset of target region in this ByteList
targetOff
,
int
length of target region in this ByteList
targetLen
,
byte[]
bytes to use for replacement
source
,
int
offset of source region in the replacement bytes
sourceOff
,
int
length of source region in the replacement bytes
sourceLen
)

Replace a region of bytes in this ByteList with a region of bytes from the given array.

public static Encoding
safeEncoding(Encoding incoming)

Ensure the encoding is always non-null.

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.

public void
set(int
to set byte
index
,
int
is the new value.
b
)

Set the byte at index to be new value.

public void
setBegin(int
the begin to set
begin
)

public void
setEncoding(Encoding
the encoding to set
encoding
)

public void
setRealSize(int
the realSize to set
realSize
)

public void
setUnsafeBytes(byte[]
the bytes to set
bytes
)

public ByteList

Returns:

a new ByteList with same backing store
shallowDup
()

Create a new ByteList but do not array copy the byte backing store.

public boolean
startsWith(ByteList other, int toffset)

public boolean

Returns:

true is this ByteList starts with other
startsWith
(ByteList
is the bytelist to compare with
other
)

Does this ByteList start with the supplied ByteList?

public CharSequence

Returns:

a new ByteList/CharSequence
subSequence
(int
index for beginning of subsequence
start
,
int
index for end of subsequence
end
)

Implements java.lang.CharSequence.subSequence.

Create subSequence of this array between start and end offsets

public String

Returns:

a String based on the raw bytes
toByteString
()

Produce a String using the raw (ISO-8859-1) bytes of this ByteList.

public String

Returns:

an ISO-8859-1 representation of the byte list
toString
()

Overrides java.lang.Object.toString.

Implements java.lang.CharSequence.toString.

Remembers toString value, which is expensive for StringBuffer.

public byte[]

Returns:

the internal byte array
unsafeBytes
()

Returns the internal byte array.

public void
unsafeReplace(int beg, int len, ByteList nbytes)

Unsafe version of replace(int,int,ByteList).

public void
unsafeReplace(int beg, int len, byte[] buf)

Unsafe version of replace(int,int,byte[]).

public void
unsafeReplace(int beg, int len, byte[] nbytes, int index, int count)

Unsafe version of replace(int,int,byte[],int,int).

public void
unshare()

Array copy the byte backing store so that you can guarantee that no other objects are referencing this objects backing store.

public void
unshare(int
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)
length
)

Array copy the byte backing store so that you can guarantee that no other objects are referencing this objects backing store.

public void
view(int
new value to add to begin
index
,
int
the new realSize/length value
len
)

Change ByteBuffer to have a new begin that is +index positions past begin with a new length.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait