public final class AppendableBytes extends Object
A mutable wrapper for an array of bytes.
Reads and writes read from and write to the wrapped byte array while advancing an internal offset.
Modifier and Type | Field and Description |
---|---|
protected byte[] |
bytes
The wrapped immutable array of bytes.
|
protected int |
offset
A mutable offset into the array of bytes.
|
Constructor and Description |
---|
AppendableBytes(byte[] bytes,
int offset)
Create AppendableBytes.
|
AppendableBytes(int size)
Create AppendableBytes.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getBytes()
Returns the bytes.
|
int |
getOffset()
Returns the offset.
|
void |
writeBoolean(boolean b)
Write a boolean.
|
void |
writeByte(byte b)
Write a byte.
|
void |
writeBytes(byte[] ba)
Write an array of bytes.
|
void |
writeBytes(byte[] ba,
int off,
int len)
Write part of an array of bytes.
|
void |
writeChar(char c)
Write a char.
|
void |
writeChars(char[] ca)
Write an array of char.
|
void |
writeDouble(double d)
Write a double.
|
void |
writeFloat(float f)
Write a float.
|
void |
writeInt(int i)
Write an int.
|
void |
writeLong(long l)
Write a long.
|
void |
writeReadableBytes(ReadableBytes readableBytes,
int length)
Write selected bytes.
|
void |
writeString(String s)
Write a string as an int and a char array.
|
protected byte[] bytes
protected int offset
public AppendableBytes(byte[] bytes, int offset)
bytes
- The bytes to be wrapped.offset
- An offset.public AppendableBytes(int size)
size
- The size of the byte array.public int getOffset()
public byte[] getBytes()
public void writeReadableBytes(ReadableBytes readableBytes, int length)
readableBytes
- The source of the bytes to be written.length
- The number of bytes to be written.public void writeByte(byte b)
b
- The byte to be written.public void writeBoolean(boolean b)
b
- The boolean to be written.public void writeBytes(byte[] ba)
ba
- The bytes to be written.public void writeBytes(byte[] ba, int off, int len)
ba
- The array containing the bytes to be written.off
- The offset to the bytes to be written.len
- The number of bytes to be written.public void writeInt(int i)
i
- The int to be written.public void writeLong(long l)
l
- The long to be written.public void writeChar(char c)
c
- The char to be written.public void writeChars(char[] ca)
ca
- The array to be written.public void writeString(String s)
s
- The string to be written, or null.public void writeFloat(float f)
f
- The float to be written.public void writeDouble(double d)
d
- The double to be written.Copyright © 2013. All Rights Reserved.