public class ByteRef
extends java.lang.Object
implements java.lang.Cloneable
A String like class to manipulate byte arrays. The most important differences to Strings:
ByteRef
share their bufferByteRef
must handle them correctly. The result is a big speed gain in data parsing
and handling.
For not yet or bad documented functions search the comment in the String class (or guess).
Constructor and Description |
---|
ByteRef()
Initializes a newly created
ByteRef object so that it represents an empty byte sequence. |
ByteRef(byte[] b)
Initializes a newly created
ByteRef object so that it represents the same sequence of bytes as the
argument; in other words, the newly created byte array is a copy of the argument. |
ByteRef(byte[] b,
int _begin,
int _end)
Initializes a newly created
ByteRef object so that it represents the same sequence of bytes as the
argument; in other words, the newly created byte array is a copy of the specified part of the argument. |
ByteRef(java.lang.String s)
Initializes a newly created
ByteRef object so that it represents the same sequence of bytes as the
argument; in other words, the newly created byte array is a copy of the argument string.getBytes(). |
Modifier and Type | Method and Description |
---|---|
void |
adjustLeft(int count)
Move the left offset by count bytes.
|
ByteRef |
append(ByteRef o)
Append the specified
ByteRef to this ByteRef . |
ByteRef |
append(java.lang.String s)
Append the bytes of the
String to this ByteRef . |
void |
assign(byte[] b,
int _begin,
int _end)
Assigns the parameters physical byte array to this object.
|
void |
assign(ByteRef o)
Assigns the parameters physical byte array to this object.
|
int |
charAt(int idx)
Returns the byte at the specified position.
|
java.lang.Object |
clone() |
int |
compareTo(ByteRef o)
Compares this
ByteRef 's data to another ByteRef . |
void |
copy(byte[] b)
Copy this data into the specified
byte array . |
int |
copy(byte[] b,
int off,
int l)
Copy a part of this data into the specified
byte array at specified offset. |
boolean |
endsWith(ByteRef o)
Tests whether this BytRef ends with the specified
ByteRef . |
boolean |
endsWith(java.lang.String s)
Tests whether this BytRef ends with the specified String.
|
boolean |
equals(java.lang.Object _o)
Compares this objects data to another object.
|
boolean |
equalsIgnoreCase(java.lang.Object _o)
Compares this objects data to another object ignoring upper and lower case.
|
int |
hashCode()
Compute a hashCode for use in Hashtable.
|
int |
indexOf(ByteRef s)
Returns the first index of the specified ByteRef's bytes.
|
int |
indexOf(ByteRef s,
int off)
Returns the first index of the specified ByteRef's bytes.
|
int |
indexOf(int z)
Returns the first index of the specified byte.
|
int |
indexOf(int z,
int off)
Returns the first index of the specified byte.
|
int |
indexOf(java.lang.String s)
Returns the first index of the specified String's bytes.
|
int |
indexOf(java.lang.String s,
int off)
Returns the first index of the specified String's bytes.
|
int |
lastIndexOf(int z)
Returns the last index of the specified byte.
|
int |
lastIndexOf(int z,
int off)
Returns the last index of the specified byte.
|
int |
length()
Return the length of this
ByteRef object. |
ByteRef |
nextLine()
Extracts the next available line from this object and returns that line as a new
BytRef object. |
ByteRef |
nextLineCRLF()
Extracts the next available line from this object and returns that line as a new
BytRef object. |
ByteRef |
nextWord()
Extracts the next available word from this object and returns that word as a new
BytRef object. |
ByteRef |
nextWord(int delim)
Extracts the content from this object up to the delimiter and returns that as a new
BytRef object. |
java.lang.String |
nextWordAsString(int delim)
Extracts the content from this object up to the delimiter and returns that as a new
BytRef object. |
static ByteRef |
readLine(ByteRef br,
java.io.InputStream is)
Extracts the next line from the specified
ByteRef br. |
static ByteRef |
readLine(ByteRef br,
java.io.RandomAccessFile is) |
int |
removeLeft()
Remove the first byte and return it as int >= 0 or return -1; This is a self modification.
|
ByteRef |
splitLeft(int stop)
Returns a ByteRef starting from 0 to stop, and removes this part from the current ByteRef.
|
ByteRef |
splitLeft(int start,
int stop)
Returns a ByteRef starting from start to stop, and removes this part from the current ByteRef.
|
boolean |
startsWith(ByteRef o)
Tests whether this BytRef starts with the specified
ByteRef . |
boolean |
startsWith(java.lang.String s)
Tests whether this BytRef starts with the specified String.
|
ByteRef |
substring(int a)
Returns a new BytRef object using only the specified part of this
ByteRef , up to end of this
ByteRef . |
ByteRef |
substring(int a,
int z)
Returns a new BytRef object using only the specified part of this
ByteRef . |
byte[] |
toByteArray()
Returns the
ByteRef s data as a new byte array. |
int |
toInteger()
Interpret the bytes as characters and convert them into an int value.
|
long |
toLong()
Interpret the bytes as characters and convert them into an long value.
|
ByteRef |
toLowerCase()
Converts upper case letters into lower case letters.
|
java.lang.String |
toString()
Returns the
ByteRef s data as a String . |
java.lang.String |
toString(int offset)
Returns the
ByteRef s data as a String starting from specified offset. |
java.lang.String |
toString(java.lang.String charset)
Returns the
ByteRef s data as a String using the specified charset. |
ByteRef |
toUpperCase()
Converts lower case letters into lower case letters.
|
ByteRef |
trim()
Remove all white spaces at begin and end.
|
ByteRef |
trim(int ch)
Remove all occurencies of the specified charater at begin and end.
|
ByteRef |
update(java.io.InputStream is)
Update this
ByteRef with the availabledata of the specified input stream. |
ByteRef |
update(java.io.RandomAccessFile raf)
Update this
ByteRef with the availabledata of the specified input stream. |
void |
writeTo(java.io.OutputStream os)
Write the bytes to the specified output stream.
|
public ByteRef()
ByteRef
object so that it represents an empty byte sequence.public ByteRef(java.lang.String s)
ByteRef
object so that it represents the same sequence of bytes as the
argument; in other words, the newly created byte array is a copy of the argument string.getBytes().s
- a String
.public ByteRef(byte[] b)
ByteRef
object so that it represents the same sequence of bytes as the
argument; in other words, the newly created byte array is a copy of the argument.b
- a byte array
.public ByteRef(byte[] b, int _begin, int _end)
ByteRef
object so that it represents the same sequence of bytes as the
argument; in other words, the newly created byte array is a copy of the specified part of the argument.b
- a byte array
._begin
- begin in the byte array_end
- end in the byte arraypublic void assign(ByteRef o)
o
- a ByteRef
public final void assign(byte[] b, int _begin, int _end)
b
- a byte array
_begin
- begin in the byte array_end
- end in the byte arraypublic final ByteRef nextLine()
BytRef
object. Unix
and DOS EOLs are recognized correctly.ByteRef
object with the next line, or null
if no EOL was found.public final ByteRef nextWord()
BytRef
object. All
bytes < 0x20 are treated as white spaces.ByteRef
object with the next word, or null
at end of buffer.public final ByteRef nextWord(int delim)
BytRef
object.
The current object is modified and contains the remaining content behind the delimiter.delim
- the used delimiterByteRef
object with the next word, or null
at end of buffer.public final java.lang.String nextWordAsString(int delim)
BytRef
object.
The current object is modified and contains the remaining content behind the delimiter.delim
- the used delimiterString
object with the next word, or null
at end of buffer.public final int length()
ByteRef
object.ByteRef
objectpublic final void copy(byte[] b)
byte array
.b
- a byte array
public final int copy(byte[] b, int off, int l)
byte array
at specified offset.b
- a byte array
off
- the offset into bl
- the copied lengthpublic final ByteRef append(ByteRef o)
ByteRef
to this ByteRef
. A new ByteRef
is allocated
and returned, to store the concatenation of both ByteRef
s.o
- the appended ByteRef
ByteRef
object with the concatenation of both ByteRef
s.public final ByteRef append(java.lang.String s)
String
to this ByteRef
. A new ByteRef
is allocated
and returned, to store the concatenation.s
- the appended String
ByteRef
object with the concatenation.public final java.lang.String toString()
ByteRef
s data as a String
.toString
in class java.lang.Object
ByteRef
s data as a String
.public final java.lang.String toString(int offset)
ByteRef
s data as a String
starting from specified offset.offset
- starting from offsetByteRef
s data as a String
.public final java.lang.String toString(java.lang.String charset)
ByteRef
s data as a String
using the specified charset.charset
- the charsetByteRef
s data as a String
.public final byte[] toByteArray()
ByteRef
s data as a new byte array.ByteRef
s data as a new byte array.public final ByteRef toUpperCase()
public final ByteRef toLowerCase()
public final int lastIndexOf(int z)
z
- the searched bytepublic final int lastIndexOf(int z, int off)
z
- the searched byteoff
- the offset (from begin) where search startspublic final int indexOf(int z)
z
- the searched bytepublic final int indexOf(int z, int off)
z
- the searched byteoff
- the offset (from begin) where search startspublic final int indexOf(java.lang.String s)
s
- the searched Stringpublic final int indexOf(java.lang.String s, int off)
s
- the searched Stringoff
- the offset (from begin) where search startspublic final int indexOf(ByteRef s, int off)
s
- the searched ByteRefoff
- the offset (from begin) where search startspublic final int indexOf(ByteRef s)
s
- the searched ByteRefpublic final ByteRef substring(int a, int z)
ByteRef
.a
- begin of used bytesz
- end of used bytesByteRef
.public final ByteRef substring(int a)
ByteRef
, up to end of this
ByteRef
.a
- begin of used bytesByteRef
.public final int charAt(int idx)
idx
- index of the bytepublic final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object _o)
equals
in class java.lang.Object
_o
- an Objectpublic final boolean equalsIgnoreCase(java.lang.Object _o)
_o
- an Objectpublic final int compareTo(ByteRef o)
ByteRef
's data to another ByteRef
.o
- a ByteRef objectByteRef
contains same data, -1 when this is less and 1 when this is greater
then the other ByteRef
.public final boolean endsWith(ByteRef o)
ByteRef
.o
- the other ByteRef
where the end is tested againstByteRef
public final boolean endsWith(java.lang.String s)
s
- the other String where the end is tested againstString
public final boolean startsWith(ByteRef o)
ByteRef
.o
- the other ByteRef
where the end is tested againstByteRef
public final boolean startsWith(java.lang.String s)
s
- the other String where the end is tested againstString
public final void writeTo(java.io.OutputStream os) throws java.io.IOException
os
- a output streamjava.io.IOException
- on io errorspublic final ByteRef trim(int ch)
ch
- a character valueByteRef
with the trimed data.public final ByteRef trim()
ByteRef
with the trimed data.public final int toInteger()
public long toLong()
public final ByteRef update(java.io.InputStream is)
ByteRef
with the availabledata of the specified input stream. current object's data
is also updated!.is
- an input streampublic final ByteRef update(java.io.RandomAccessFile raf)
ByteRef
with the availabledata of the specified input stream. current object's data
is also updated!.raf
- an input streampublic static final ByteRef readLine(ByteRef br, java.io.InputStream is)
ByteRef
br. If there is no complete line in br, the
ByteRef
is updated using the specified input stream. This is done until a complete line is read, or
br.update(is) fails.br
- the ByteRef
used as input bufferis
- a input streamByteRef
containing the next line, or null on EOS.public final java.lang.Object clone()
clone
in class java.lang.Object
public final ByteRef splitLeft(int stop)
stop
- end positionpublic final ByteRef splitLeft(int start, int stop)
start
- start position for returned ByteRefstop
- stop position for returned ByteRefpublic final int removeLeft()
public final void adjustLeft(int count)
count
- the count of bytes to remove from left side.public final ByteRef nextLineCRLF()
BytRef
object. Only
DOS EOLs are recognized correctly.ByteRef
object with the next line, or null
if no EOL was found.