Package one.microstream.bytes
Class VarByte
java.lang.Object
one.microstream.bytes.VarByte
- All Implemented Interfaces:
Externalizable
,Serializable
public final class VarByte extends Object implements Externalizable
- See Also:
- Serialized Form
-
Method Summary
Modifier and Type Method Description VarByte
add(boolean b)
VarByte
add(byte c)
VarByte
add(byte[] bytes)
VarByte
add(double d)
VarByte
add(float f)
VarByte
add(int i)
VarByte
add(long l)
VarByte
add(short s)
VarByte
add(String s)
VarByte
add(VarByte varByte)
VarByte
append(boolean value)
VarByte
append(byte value)
VarByte
append(byte[] bytes)
VarByte
append(byte[] bytes, int offset, int length)
VarByte
append(char value)
VarByte
append(double value)
VarByte
append(float value)
VarByte
append(int value)
VarByte
append(long value)
VarByte
append(short value)
VarByte
appendArray(byte... bytes)
VarByte
apply(Consumer<? super VarByte> procedure)
VarByte
clear()
Only preferable toreset()
for security reasons.boolean
contains(byte c)
int
count(byte c)
VarByte
deleteByteAt(int index)
VarByte
deleteLast(int n)
VarByte
deleteLastByte()
void
ensureFreeCapacity(int requiredFreeCapacity)
byte
firstByte()
byte
get(int index)
void
getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
static boolean
hasContent(VarByte varByte)
static boolean
hasNoContent(VarByte varByte)
int
indexOf(byte c)
int
indexOf(byte[] bytes)
int
indexOf(byte[] bytes, int offset)
int
indexOf(byte c, int fromIndex)
boolean
isEmpty()
byte
lastByte()
int
lastIndexOf(byte c)
int
lastIndexOf(byte c, int fromIndex)
int
length()
static VarByte
New()
static VarByte
New(int initialCapacity)
Use this constructor only if really a specific size is needed or list of bytes to be handled is huge.
Otherwise, use the factory methods as they are faster due to skipping capacity checks and bounds adjustment.VarByte
printlnTo(PrintStream printStream)
Passes a copy of the internal byte array to thePrintStream.println(String)
method of the passedPrintStream
instance.VarByte
printTo(PrintStream printStream)
Passes a copy of the internal byte array to thePrintStream.print(String)
method of the passedPrintStream
instance.void
process(_byteProcedure processor)
void
readExternal(ObjectInput in)
VarByte
repeat(int amount, byte b)
VarByte
replaceFirst(byte sample, byte replacement)
VarByte
replaceFirst(int beginIndex, byte sample, byte replacement)
VarByte
reset()
VarByte
reverse()
VarByte
setByte(int index, byte c)
VarByte
setBytes(int index, byte... c)
VarByte
setLastByte(byte c)
VarByte
shrinkTo(int n)
VarByte
subsequence(int beginIndex, int endIndex)
VarByte
subSequence(int start, int end)
VarByte
surrogateByteReverse()
Deprecated.not implemented yet.byte[]
toByteArray()
String
toString()
String
toString(Charset charset)
void
trimToSize()
void
truncate()
void
writeExternal(ObjectOutput out)
-
Method Details
-
New
-
New
Use this constructor only if really a specific size is needed or list of bytes to be handled is huge.
Otherwise, use the factory methods as they are faster due to skipping capacity checks and bounds adjustment.
Note that the given
initialCapacity
will still be adjusted to the next higher 2^n bounding value.- Parameters:
initialCapacity
- the initial size of the buffer- Returns:
- a new VarByte instance
-
get
public byte get(int index) -
lastByte
public byte lastByte() -
firstByte
public byte firstByte() -
length
public int length() -
subSequence
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
toString
-
toString
- Throws:
UnsupportedEncodingException
-
add
-
add
-
add
-
add
-
add
-
add
-
add
-
add
-
add
-
add
-
ensureFreeCapacity
public void ensureFreeCapacity(int requiredFreeCapacity) -
appendArray
-
append
-
append
-
append
-
append
-
append
-
append
-
append
-
append
-
append
-
append
-
setByte
-
setBytes
-
setLastByte
-
reverse
-
surrogateByteReverse
Deprecated.not implemented yet. Currently just doesreverse()
.Not implemented yet. -
indexOf
public int indexOf(byte c) -
indexOf
public int indexOf(byte c, int fromIndex) -
indexOf
public int indexOf(byte[] bytes) -
indexOf
public int indexOf(byte[] bytes, int offset) -
contains
public boolean contains(byte c) -
lastIndexOf
public int lastIndexOf(byte c) -
lastIndexOf
public int lastIndexOf(byte c, int fromIndex) -
count
public int count(byte c) -
deleteByteAt
-
deleteLastByte
-
deleteLast
-
shrinkTo
-
toByteArray
public byte[] toByteArray() -
getBytes
public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) -
isEmpty
public boolean isEmpty() -
trimToSize
public void trimToSize() -
hasNoContent
- Parameters:
varByte
- the VarByte to check- Returns:
true
ifvarByte
is eithernull
or empty.- See Also:
isEmpty()
-
hasContent
-
replaceFirst
-
replaceFirst
-
subsequence
-
process
-
clear
Only preferable toreset()
for security reasons.- Returns:
- this
-
reset
-
truncate
public void truncate() -
printlnTo
Passes a copy of the internal byte array to thePrintStream.println(String)
method of the passedPrintStream
instance.The purpose of this method is to spare the unnecessary String instantiation of the generic method
PrintStream.println(Object)
.- Parameters:
printStream
- thePrintStream
instance to be written to.- Returns:
- this
VarByte
instance.
-
printTo
Passes a copy of the internal byte array to thePrintStream.print(String)
method of the passedPrintStream
instance.The purpose of this method is to spare the unnecessary String instantiation of the generic method
PrintStream.println(Object)
.- Parameters:
printStream
- thePrintStream
instance to be written to.- Returns:
- this
VarByte
instance.
-
repeat
-
apply
-