Class ByteArrayBuilder
- java.lang.Object
- 
- org.opends.server.replication.protocol.ByteArrayBuilder
 
- 
 public final class ByteArrayBuilder extends Object Byte array builder class encodes data into byte arrays to send messages over the replication protocol. Built on top ofByteStringBuilder, it isolates the latter against legacy type conversions from the replication protocol. It exposes a fluent API.
- 
- 
Constructor SummaryConstructors Constructor Description ByteArrayBuilder()Constructs a ByteArrayBuilder.ByteArrayBuilder(int capacity)Constructs a ByteArrayBuilder.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteArrayBuilderappendBoolean(boolean b)Append a boolean to this ByteArrayBuilder.ByteArrayBuilderappendByte(int b)Append a byte to this ByteArrayBuilder.ByteArrayBuilderappendByteArray(byte[] bytes)Append all the bytes from the byte array to this ByteArrayBuilder.ByteArrayBuilderappendCsn(CSN csn, CSN.CsnVersion version)Append a CSN to this ByteArrayBuilder.ByteArrayBuilderappendCsnUtf8(CSN csn, CSN.CsnVersion version)Append a CSN to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte array.ByteArrayBuilderappendDn(Dn dn)Append a DN to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte array.ByteArrayBuilderappendGroupId(com.forgerock.opendj.discovery.GroupId groupId)Appends the encoded version of aGroupIdto this ByteArrayBuilder.ByteArrayBuilderappendInt(int i)Append an int to this ByteArrayBuilder.ByteArrayBuilderappendIntUtf8(int i)Append an int to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte array.ByteArrayBuilderappendLong(long l)Append a long to this ByteArrayBuilder.ByteArrayBuilderappendLongUtf8(long l)Append a long to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte array.ByteArrayBuilderappendRdn(Rdn rdn)Append an RDN to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte array.ByteArrayBuilderappendReplicaId(ReplicaId replicaId)Appends the encoded version of thisReplicaIdto this ByteArrayBuilder.ByteArrayBuilderappendReplicationServerId(ReplicationServerId replicationServerId)Appends the encoded version of thisReplicationServerIdto this ByteArrayBuilder.ByteArrayBuilderappendServerId(ServerId<?> serverId)Appends a server id.ByteArrayBuilderappendServerStateMustComeLast(ServerState serverState)Append the byte representation of a ServerState to this ByteArrayBuilder and then append a final zero byte separator.ByteArrayBuilderappendShort(int s)Append a short to this ByteArrayBuilder.ByteArrayBuilderappendString(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.ByteArrayBuilderappendStrings(Collection<String> col)Append a Collection of Strings to this ByteArrayBuilder.ByteArrayBuilderappendUUID(UUID uuid)Append an UUID with a zero separator to this ByteArrayBuilder, or only the zero separator if the UUID isnull.ByteArrayBuilderappendZeroTerminatedByteArray(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 intbytes(int nbFields)Helper method that returns the number of bytes that would be used by the byte fields when appended to a ByteArrayBuilder.static intcsnsV1(int nbFields)Helper method that returns the number of bytes that would be used by the CSN fields when appended to a ByteArrayBuilder.Asn1WritergetAsn1Writer()Returns a new ASN1Writer that will append bytes to this ByteArrayBuilder.static intshorts(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.StringtoString()
 
- 
- 
- 
Method Detail- 
appendBooleanpublic ByteArrayBuilder appendBoolean(boolean b) Append a boolean to this ByteArrayBuilder.- Parameters:
- b- the boolean to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendBytepublic ByteArrayBuilder appendByte(int b) Append a byte to this ByteArrayBuilder.- Parameters:
- b- the byte to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendShortpublic ByteArrayBuilder appendShort(int s) Append a short to this ByteArrayBuilder.- Parameters:
- s- the short to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendIntpublic ByteArrayBuilder appendInt(int i) Append an int to this ByteArrayBuilder.- Parameters:
- i- the long to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendLongpublic ByteArrayBuilder appendLong(long l) Append a long to this ByteArrayBuilder.- Parameters:
- l- the long to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendIntUtf8public 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.- Parameters:
- i- the int to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendLongUtf8public 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.- Parameters:
- l- the long to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendStringspublic ByteArrayBuilder appendStrings(Collection<String> col) Append a Collection of Strings to this ByteArrayBuilder.- Parameters:
- col- the Collection of Strings to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendStringpublic 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.- Parameters:
- s- the String to append. Can be null.
- Returns:
- this ByteArrayBuilder
 
 - 
appendUUIDpublic ByteArrayBuilder appendUUID(UUID uuid) Append an UUID with a zero separator to this ByteArrayBuilder, or only the zero separator if the UUID isnull.- Parameters:
- uuid- the UUID to append. Can be- null.
- Returns:
- this ByteArrayBuilder
 
 - 
appendGroupIdpublic ByteArrayBuilder appendGroupId(com.forgerock.opendj.discovery.GroupId groupId) Appends the encoded version of aGroupIdto this ByteArrayBuilder.- Parameters:
- groupId- the group id to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendReplicaIdpublic ByteArrayBuilder appendReplicaId(ReplicaId replicaId) Appends the encoded version of thisReplicaIdto this ByteArrayBuilder.- Parameters:
- replicaId- the replica id to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendReplicationServerIdpublic ByteArrayBuilder appendReplicationServerId(ReplicationServerId replicationServerId) Appends the encoded version of thisReplicationServerIdto this ByteArrayBuilder.- Parameters:
- replicationServerId- the replication server id to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendServerIdpublic ByteArrayBuilder appendServerId(ServerId<?> serverId) Appends a server id.- Parameters:
- serverId- the- ServerIdto append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendCsnpublic ByteArrayBuilder appendCsn(CSN csn, CSN.CsnVersion version) Append a CSN to this ByteArrayBuilder.- Parameters:
- csn- the CSN to append.
- version- the CSN version to use for encoding
- Returns:
- this ByteArrayBuilder
 
 - 
appendCsnUtf8public ByteArrayBuilder appendCsnUtf8(CSN csn, CSN.CsnVersion version) Append a CSN to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte array.- Parameters:
- csn- the CSN to append.
- version- the CSN version to use for encoding.
- Returns:
- this ByteArrayBuilder
 
 - 
appendDnpublic 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.- Parameters:
- dn- the DN to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendRdnpublic ByteArrayBuilder appendRdn(Rdn rdn) Append an RDN to this ByteArrayBuilder by converting it to a String then encoding that string to a UTF-8 byte array.- Parameters:
- rdn- the RDN to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendByteArraypublic ByteArrayBuilder appendByteArray(byte[] bytes) Append all the bytes from the byte array to this ByteArrayBuilder.- Parameters:
- bytes- the byte array to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendZeroTerminatedByteArraypublic 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.Note: the super long method name it is intentional: nobody will want to use it, which is good because nobody should. - Parameters:
- bytes- the byte array to append.
- Returns:
- this ByteArrayBuilder
 
 - 
appendServerStateMustComeLastpublic ByteArrayBuilder appendServerStateMustComeLast(ServerState serverState) Append the byte representation of a ServerState to this ByteArrayBuilder and then append a final zero byte separator.Caution: ServerState MUST be the last field. Because ServerState can contain null character (string termination of replica id 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. - Parameters:
- serverState- the ServerState to append.
- Returns:
- this ByteArrayBuilder
- See Also:
- ByteArrayScanner.nextServerStateMustComeLast()
 
 - 
getAsn1Writerpublic Asn1Writer getAsn1Writer() Returns a new ASN1Writer that will append bytes to this ByteArrayBuilder.- Returns:
- a new ASN1Writer that will append bytes to this ByteArrayBuilder.
 
 - 
toByteArraypublic byte[] toByteArray() Converts the content of this ByteStringBuilder to a byte array.- Returns:
- the content of this ByteStringBuilder converted to a byte array.
 
 - 
bytespublic 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.- Parameters:
- nbFields- the number of byte fields that will be appended to a ByteArrayBuilder
- Returns:
- the number of bytes occupied by the appended byte fields.
 
 - 
shortspublic 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.- Parameters:
- nbFields- the number of short fields that will be appended to a ByteArrayBuilder
- Returns:
- the number of bytes occupied by the appended short fields.
 
 - 
csnsV1public static int csnsV1(int nbFields) Helper method that returns the number of bytes that would be used by the CSN fields when appended to a ByteArrayBuilder.- Parameters:
- nbFields- the number of CSN fields that will be appended to a ByteArrayBuilder
- Returns:
- the number of bytes occupied by the appended CSN fields.
 
 
- 
 
-