use of org.apache.directory.api.asn1.util.BitString in project directory-ldap-api by apache.
the class ValueTest method testEncodeBitString.
@Test
public void testEncodeBitString() {
BitString bs = new BitString(10);
bs.setBit(9);
ByteBuffer buffer = ByteBuffer.allocate(5);
try {
BerValue.encode(buffer, bs);
} catch (EncoderException ee) {
fail();
}
assertEquals("0x03 0x03 0x06 0x00 0x40 ", Asn1StringUtils.dumpBytes(buffer.array()));
}
use of org.apache.directory.api.asn1.util.BitString in project directory-ldap-api by apache.
the class BerValue method encode.
/**
* Encode a BIT STRING value
*
* @param buffer The PDU in which the value will be put
* @param bitString The BitString to be encoded.
* @throws EncoderException if the PDU in which the value should be encoded is
* two small
*/
public static void encode(ByteBuffer buffer, BitString bitString) throws EncoderException {
if (buffer == null) {
throw new EncoderException(I18n.err(I18n.ERR_01300_CANNOT_PUT_PDU_IN_NULL_BUFFER));
}
try {
buffer.put(UniversalTag.BIT_STRING.getValue());
// The BitString length. We add one byte for the unused number
// of bits
byte[] bytes = bitString.getData();
int length = bytes.length;
buffer.put(TLV.getBytes(length));
buffer.put(bytes);
} catch (BufferOverflowException boe) {
throw new EncoderException(I18n.err(I18n.ERR_01301_PDU_BUFFER_SIZE_TOO_SMALL), boe);
}
}
Aggregations