Class ByteArrayScanner
- java.lang.Object
-
- org.opends.server.replication.protocol.ByteArrayScanner
-
public final class ByteArrayScanner extends Object
Byte array scanner class helps decode data from byte arrays received via messages over the replication protocol. Built on top ofByteStringReader
, it isolates the latter against legacy type conversions from the replication protocol.
-
-
Constructor Summary
Constructors Constructor Description ByteArrayScanner(byte[] bytes)
Builds a ByteArrayScanner object that will read from the supplied byte array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Asn1Reader
getAsn1Reader()
Returns a new ASN1Reader that will read bytes from this ByteArrayScanner.boolean
isEmpty()
Returns whether the scanner has more bytes to consume.boolean
nextBoolean()
Reads the next boolean.byte
nextByte()
Reads the next byte.byte[]
nextByteArray(int length)
Return a new byte array containing the requested number of bytes.CSN
nextCsn()
Reads the next CSN.CSN
nextCsnUtf8()
Reads the next CSN that was encoded as a UTF8 string.Dn
nextDn()
Reads the next DN.com.forgerock.opendj.discovery.GroupId
nextGroupId()
Reads the next group id.int
nextInt()
Reads the next int.int
nextIntUtf8()
Reads the next int that was encoded as a UTF8 string.long
nextLong()
Reads the next long.long
nextLongUtf8()
Reads the next long that was encoded as a UTF8 string.Rdn
nextRdn()
Reads the next RDN.ReplicaId
nextReplicaId()
Reads the next replica id.ReplicationServerId
nextReplicationServerId()
Reads the next replication server id.ServerId<?>
nextServerId()
Reads the next replication server id or replica id.ServerState
nextServerStateMustComeLast()
Reads the next ServerState.short
nextShort()
Reads the next short.String
nextString()
Reads the next UTF8-encoded string.<T extends Collection<String>>
TnextStrings(T output)
Reads the next UTF8-encoded strings in the provided collection.UUID
nextUUID()
Reads the next UUID.byte[]
remainingBytes()
Return a new byte array containing all remaining bytes in this ByteArrayScanner.byte[]
remainingBytesZeroTerminated()
Return a new byte array containing all remaining bytes in this ByteArrayScanner bar the last one which is a zero terminated byte (compatible with legacy code).void
skipZeroSeparator()
Skips the next byte and verifies it is effectively the zero separator.String
toString()
-
-
-
Method Detail
-
nextBoolean
public boolean nextBoolean() throws DataFormatException
Reads the next boolean.- Returns:
- the next boolean
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextByte
public byte nextByte() throws DataFormatException
Reads the next byte.- Returns:
- the next byte
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextShort
public short nextShort() throws DataFormatException
Reads the next short.- Returns:
- the next short
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextInt
public int nextInt() throws DataFormatException
Reads the next int.- Returns:
- the next int
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextLong
public long nextLong() throws DataFormatException
Reads the next long.- Returns:
- the next long
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextIntUtf8
public int nextIntUtf8() throws DataFormatException
Reads the next int that was encoded as a UTF8 string.- Returns:
- the next int that was encoded as a UTF8 string.
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextLongUtf8
public long nextLongUtf8() throws DataFormatException
Reads the next long that was encoded as a UTF8 string.- Returns:
- the next long that was encoded as a UTF8 string.
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextString
public String nextString() throws DataFormatException
Reads the next UTF8-encoded string.- Returns:
- the next UTF8-encoded string or null if the string length is zero
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextUUID
public UUID nextUUID() throws DataFormatException
Reads the next UUID.- Returns:
- the next UUID or
null
if there is no UUID - Throws:
DataFormatException
- if no more data can be read from the input
-
nextStrings
public <T extends Collection<String>> T nextStrings(T output) throws DataFormatException
Reads the next UTF8-encoded strings in the provided collection.- Type Parameters:
T
- the collection's concrete type- Parameters:
output
- the collection where to add the next UTF8-encoded strings- Returns:
- the provided collection where the next UTF8-encoded strings have been added.
- Throws:
DataFormatException
- if no more data can be read from the input
-
nextGroupId
public com.forgerock.opendj.discovery.GroupId nextGroupId() throws DataFormatException
Reads the next group id.- Returns:
- the next group id.
- Throws:
DataFormatException
- if group id was incorrectly encoded or no more data can be read from the input
-
nextReplicationServerId
public ReplicationServerId nextReplicationServerId() throws DataFormatException
Reads the next replication server id.- Returns:
- the next replication server id.
- Throws:
DataFormatException
- if a replication server id is not present or no more data can be read from the input
-
nextServerId
public ServerId<?> nextServerId() throws DataFormatException
Reads the next replication server id or replica id.- Returns:
- the next
ReplicaId
orReplicationServerId
- Throws:
DataFormatException
- if a neither a replica id or replication server id is not present, or no more data can be read from the input
-
nextReplicaId
public ReplicaId nextReplicaId() throws DataFormatException
Reads the next replica id.- Returns:
- the next replica id.
- Throws:
DataFormatException
- if a replica id is not present or no more data can be read from the input
-
nextCsn
public CSN nextCsn() throws DataFormatException
Reads the next CSN.- Returns:
- the next CSN.
- Throws:
DataFormatException
- if CSN was incorrectly encoded or no more data can be read from the input
-
nextCsnUtf8
public CSN nextCsnUtf8() throws DataFormatException
Reads the next CSN that was encoded as a UTF8 string.- Returns:
- the next CSN that was encoded as a UTF8 string.
- Throws:
DataFormatException
- if legacy CSN was incorrectly encoded or no more data can be read from the input
-
nextDn
public Dn nextDn() throws DataFormatException
Reads the next DN.- Returns:
- the next DN or
null
if there is no DN. - Throws:
DataFormatException
- if DN was incorrectly encoded or no more data can be read from the input
-
nextRdn
public Rdn nextRdn() throws DataFormatException
Reads the next RDN.- Returns:
- the next RDN or
null
if there is no RDN. - Throws:
DataFormatException
- if DN was incorrectly encoded or no more data can be read from the input
-
remainingBytes
public byte[] remainingBytes()
Return a new byte array containing all remaining bytes in this ByteArrayScanner.- Returns:
- new byte array containing all remaining bytes
-
remainingBytesZeroTerminated
public byte[] remainingBytesZeroTerminated()
Return a new byte array containing all remaining bytes in this ByteArrayScanner bar the last one which is a zero terminated byte (compatible with legacy code).- Returns:
- new byte array containing all remaining bytes bar the last one
-
nextByteArray
public byte[] nextByteArray(int length)
Return a new byte array containing the requested number of bytes.- Parameters:
length
- the number of bytes to be read and copied to the new byte array.- Returns:
- new byte array containing the requested number of bytes.
-
nextServerStateMustComeLast
public ServerState nextServerStateMustComeLast() throws DataFormatException
Reads the next ServerState.Caution: ServerState MUST be the last field (see
ByteArrayBuilder.appendServerStateMustComeLast(ServerState)
javadoc).Note: the super long method name it is intentional: nobody will want to use it, which is good because nobody should.
- Returns:
- the next ServerState.
- Throws:
DataFormatException
- if ServerState was incorrectly encoded or no more data can be read from the input- See Also:
ByteArrayBuilder.appendServerStateMustComeLast(ServerState)
-
skipZeroSeparator
public void skipZeroSeparator() throws DataFormatException
Skips the next byte and verifies it is effectively the zero separator.- Throws:
DataFormatException
- if the next byte is not the zero separator.
-
getAsn1Reader
public Asn1Reader getAsn1Reader()
Returns a new ASN1Reader that will read bytes from this ByteArrayScanner.- Returns:
- a new ASN1Reader that will read bytes from this ByteArrayScanner.
-
isEmpty
public boolean isEmpty()
Returns whether the scanner has more bytes to consume.- Returns:
- true if the scanner has more bytes to consume, false otherwise.
-
-