public class ByteArrayBuilder extends Object
ByteStringBuilder
, it isolates the latter against legacy type conversions from the replication protocol.
It exposes a fluent API.Constructor and Description |
---|
ByteArrayBuilder()
Constructs a ByteArrayBuilder.
|
ByteArrayBuilder(int capacity)
Constructs a ByteArrayBuilder.
|
Modifier and Type | Method and Description |
---|---|
ByteArrayBuilder |
appendBoolean(boolean b)
Append a boolean to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendByte(int b)
Append a byte to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendByteArray(byte[] bytes)
Append all the bytes from the byte array to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendCSN(CSN csn)
Append a CSN to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendCSNUTF8(CSN csn)
Append a CSN to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte
array.
|
ByteArrayBuilder |
appendDN(Dn dn)
Append a DN to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte
array.
|
ByteArrayBuilder |
appendInt(int i)
Append an int to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendIntUTF8(int i)
Append an int to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte
array.
|
ByteArrayBuilder |
appendLong(long l)
Append a long to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendLongUTF8(long l)
Append a long to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte
array.
|
ByteArrayBuilder |
appendServerStateMustComeLast(ServerState serverState)
Append the byte representation of a ServerState to this ByteArrayBuilder and then append a final zero byte
separator.
|
ByteArrayBuilder |
appendShort(int s)
Append a short to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendString(String s)
Append a String with a zero separator to this ByteArrayBuilder, or only the zero separator if the string is null
or if the string length is zero.
|
ByteArrayBuilder |
appendStrings(Collection<String> col)
Append a Collection of Strings to this ByteArrayBuilder.
|
ByteArrayBuilder |
appendZeroTerminatedByteArray(byte[] bytes)
Append all the bytes from the byte array to this ByteArrayBuilder and then append a final zero byte separator for
compatibility with legacy implementations.
|
static int |
booleans(int nbFields)
Helper method that returns the number of bytes that would be used by the boolean fields when appended to a
ByteArrayBuilder.
|
static int |
bytes(int nbFields)
Helper method that returns the number of bytes that would be used by the byte fields when appended to a
ByteArrayBuilder.
|
static int |
csns(int nbFields)
Helper method that returns the number of bytes that would be used by the CSN fields when appended to a
ByteArrayBuilder.
|
static int |
csnsUTF8(int nbFields)
Helper method that returns the number of bytes that would be used by the CSN fields encoded as a UTF8 string when
appended to a ByteArrayBuilder.
|
Asn1Writer |
getASN1Writer()
Returns a new ASN1Writer that will append bytes to this ByteArrayBuilder.
|
static int |
ints(int nbFields)
Helper method that returns the number of bytes that would be used by the int fields when appended to a
ByteArrayBuilder.
|
static int |
longs(int nbFields)
Helper method that returns the number of bytes that would be used by the long fields when appended to a
ByteArrayBuilder.
|
static int |
shorts(int nbFields)
Helper method that returns the number of bytes that would be used by the short fields when appended to a
ByteArrayBuilder.
|
byte[] |
toByteArray()
Converts the content of this ByteStringBuilder to a byte array.
|
String |
toString() |
public ByteArrayBuilder()
public ByteArrayBuilder(int capacity)
capacity
- the capacity of the underlying ByteStringBuilderpublic ByteArrayBuilder appendBoolean(boolean b)
b
- the boolean to append.public ByteArrayBuilder appendByte(int b)
b
- the byte to append.public ByteArrayBuilder appendShort(int s)
s
- the short to append.public ByteArrayBuilder appendInt(int i)
i
- the long to append.public ByteArrayBuilder appendLong(long l)
l
- the long to append.public ByteArrayBuilder appendIntUTF8(int i)
i
- the int to append.public ByteArrayBuilder appendLongUTF8(long l)
l
- the long to append.public ByteArrayBuilder appendStrings(Collection<String> col)
col
- the Collection of Strings to append.public ByteArrayBuilder appendString(String s)
s
- the String to append. Can be null.public ByteArrayBuilder appendCSN(CSN csn)
csn
- the CSN to append.public ByteArrayBuilder appendCSNUTF8(CSN csn)
csn
- the CSN to append.public ByteArrayBuilder appendDN(Dn dn)
dn
- the DN to append.public ByteArrayBuilder appendByteArray(byte[] bytes)
bytes
- the byte array to append.public ByteArrayBuilder appendZeroTerminatedByteArray(byte[] bytes)
Note: the super long method name it is intentional: nobody will want to use it, which is good because nobody should.
bytes
- the byte array to append.public ByteArrayBuilder appendServerStateMustComeLast(ServerState serverState)
Caution: ServerState MUST be the last field. Because ServerState can contain null character (string termination
of serverId string ..) it cannot be decoded using ByteArrayScanner.nextString()
like the other fields.
The only way is to rely on the end of the input buffer: and that forces the ServerState to be the last field.
This should be changed if we want to have more than one ServerState field.
Note: the super long method name it is intentional: nobody will want to use it, which is good because nobody should.
serverState
- the ServerState to append.ByteArrayScanner.nextServerStateMustComeLast()
public Asn1Writer getASN1Writer()
public byte[] toByteArray()
public static int booleans(int nbFields)
nbFields
- the number of boolean fields that will be appended to a ByteArrayBuilderpublic static int bytes(int nbFields)
nbFields
- the number of byte fields that will be appended to a ByteArrayBuilderpublic static int shorts(int nbFields)
nbFields
- the number of short fields that will be appended to a ByteArrayBuilderpublic static int ints(int nbFields)
nbFields
- the number of int fields that will be appended to a ByteArrayBuilderpublic static int longs(int nbFields)
nbFields
- the number of long fields that will be appended to a ByteArrayBuilderpublic static int csns(int nbFields)
nbFields
- the number of CSN fields that will be appended to a ByteArrayBuilderpublic static int csnsUTF8(int nbFields)
nbFields
- the number of CSN fields that will be appended to a ByteArrayBuilderCopyright 2010-2018 ForgeRock AS.