public class Slice extends Object implements Comparable<Slice>, Stringable
Modifier and Type | Field and Description |
---|---|
protected byte[] |
fb |
protected int |
len |
protected int |
off |
Constructor and Description |
---|
Slice(byte[] fb,
int off,
int len)
Create a slice instance.
|
Modifier and Type | Method and Description |
---|---|
String |
asString()
Get the whole slice as a string.
|
char |
charAt(int i)
Get character at slice relative position.
|
int |
compareTo(Slice o)
Compare slice with other slice.
|
boolean |
contains(byte a)
Checks if a single byte can be found in the slice.
|
boolean |
contains(byte[] a)
Checks if the byte array is contained in the slice.
|
boolean |
containsAny(byte... a)
Checks if any of the provided bytes is contained in the slice.
|
boolean |
equals(Object o) |
int |
hashCode() |
int |
length()
Get the total length of the slice.
|
double |
parseDouble()
Get the whole slice as a real number.
|
long |
parseInteger()
Get the whole slice as a simple integer.
|
boolean |
strEquals(byte[] a)
Checks if the slice is equal to given byte array.
|
boolean |
strEquals(byte[] a,
int aOff,
int aLen)
Checks if the slice is equal to a portion of a given byte array.
|
Slice |
substring(int start,
int end)
Create a substring slice based on the current slice.
|
String |
toString() |
public Slice(byte[] fb, int off, int len)
fb
- The buffer to wrap.off
- The start offset to wrap.len
- The length to represent.public final int length()
public final String asString()
asString
in interface Stringable
public final Slice substring(int start, int end)
start
- The internal start position, relative to the slice's offset.end
- The internal end position, relative to the slice's offset. If end
is negative, then it is relative to the slice's end position.public final char charAt(int i)
i
- The position to get. If negative is relative to the slice's end position.public final long parseInteger()
public final double parseDouble()
public boolean strEquals(byte[] a)
a
- The array to compare with.public boolean strEquals(byte[] a, int aOff, int aLen)
a
- The array to compare with.aOff
- The offset to compare with in the array.aLen
- The length to compare with.public boolean containsAny(byte... a)
a
- Bytes to find in the slice.public boolean contains(byte[] a)
a
- The byte array to find.public boolean contains(byte a)
a
- The byte to find.public int compareTo(Slice o)
compareTo
in interface Comparable<Slice>
o
- The other slice.Copyright © 2017. All rights reserved.