APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.jndi.ldap

public final Class BerEncoder

extends Ber
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.ISO_8859_1, .StandardCharsets.UTF_8

A BER encoder.
Authors
Jagane Sundar, Scott Seligman, Vincent Ryan

Field Summary

Modifier and TypeField and Description
private static final int
private int
private static final int
private static final int
private int[]
Inherited from com.sun.jndi.ldap.Ber:
ASN_APPLICATIONASN_BIT_STRINGASN_BOOLEANASN_CONSTRUCTORASN_CONTEXTASN_ENUMERATEDASN_INTEGERASN_NULLASN_OBJECT_IDASN_OCTET_STRASN_PRIMITIVEASN_PRIVATEASN_SEQUENCEASN_SETASN_SIMPLE_STRINGASN_UNIVERSALbufbufsizeoffset

Constructor Summary

AccessConstructor and Description
public
BerEncoder()

Creates a BER buffer for encoding.

public
BerEncoder(int
The number of bytes for the buffer.
bufsize
)

Creates a BER buffer of a specified size for encoding.

Method Summary

Modifier and TypeMethod and Description
public void
beginSeq(int tag)

Begin encoding a sequence with a tag.

public void
encodeBoolean(boolean b)

Encodes a boolean.

public void
encodeBoolean(boolean b, int tag)

Encodes a boolean and a tag

 BER boolean w TAG ::= tag 0x01 {0xff|0x00}
public void
encodeByte(int b)

Encode a single byte.

public void
encodeInt(int i)

public void
encodeInt(int i, int tag)

Encodes an int and a tag.

private void
encodeInt(int i, int tag, int intsize)

private void
encodeLength(int len)

public void
encodeOctetString(byte[] tb, int tag, int tboffset, int length)

Encodes a portion of an octet string and a tag.

public void
encodeOctetString(byte[] tb, int tag)

Encodes an octet string and a tag.

public void
encodeString(String str, boolean encodeUTF8)

Encodes a string.

public void
encodeString(String str, int tag, boolean encodeUTF8)

Encodes a string and a tag.

public void
encodeStringArray(String[] strs, boolean encodeUTF8)

Encodes an array of strings.

public void
endSeq()

Terminate a BER sequence.

private void
ensureFreeBytes(int len)

Ensures that there are at least "len" unused bytes in "buf".

public byte[]
getBuf()

Gets the buffer that contains the BER encoding.

public int
getDataLen()

Gets the number of encoded bytes in this BER buffer.

public byte[]
getTrimmedBuf()

Gets the buffer that contains the BER encoding, trimming unused bytes.

public void
reset()

Resets encoder to state when newly constructed.

private void
shiftSeqData(int start, int len, int shift)

Shifts contents of buf in the range [start,start+len) a specified amount.

Inherited from com.sun.jndi.ldap.Ber:
dumpBER

Field Detail

BUF_GROWTH_FACTORback to summary
private static final int BUF_GROWTH_FACTOR
curSeqIndexback to summary
private int curSeqIndex
DEFAULT_BUFSIZEback to summary
private static final int DEFAULT_BUFSIZE
INITIAL_SEQUENCESback to summary
private static final int INITIAL_SEQUENCES
seqOffsetback to summary
private int[] seqOffset

Constructor Detail

BerEncoderback to summary
public BerEncoder()

Creates a BER buffer for encoding.

BerEncoderback to summary
public BerEncoder(int bufsize)

Creates a BER buffer of a specified size for encoding. Specify the initial bufsize. Buffer will be expanded as needed.

Parameters
bufsize:int

The number of bytes for the buffer.

Method Detail

beginSeqback to summary
public void beginSeq(int tag)

Begin encoding a sequence with a tag.

encodeBooleanback to summary
public void encodeBoolean(boolean b)

Encodes a boolean.

 BER boolean ::= 0x01 0x01 {0xff|0x00}
encodeBooleanback to summary
public void encodeBoolean(boolean b, int tag)

Encodes a boolean and a tag

 BER boolean w TAG ::= tag 0x01 {0xff|0x00}
encodeByteback to summary
public void encodeByte(int b)

Encode a single byte.

encodeIntback to summary
public void encodeInt(int i)
encodeIntback to summary
public void encodeInt(int i, int tag)

Encodes an int and a tag.

 BER integer w tag ::= tag berlength byte {byte}*
encodeIntback to summary
private void encodeInt(int i, int tag, int intsize)
encodeLengthback to summary
private void encodeLength(int len) throws EncodeException
encodeOctetStringback to summary
public void encodeOctetString(byte[] tb, int tag, int tboffset, int length) throws EncodeException

Encodes a portion of an octet string and a tag.

encodeOctetStringback to summary
public void encodeOctetString(byte[] tb, int tag) throws EncodeException

Encodes an octet string and a tag.

encodeStringback to summary
public void encodeString(String str, boolean encodeUTF8) throws EncodeException

Encodes a string.

 BER string ::= 0x04 strlen byte1 byte2...
The string is converted into bytes using UTF-8 or ISO-Latin-1.
encodeStringback to summary
public void encodeString(String str, int tag, boolean encodeUTF8) throws EncodeException

Encodes a string and a tag.

 BER string w TAG ::= tag strlen byte1 byte2...
encodeStringArrayback to summary
public void encodeStringArray(String[] strs, boolean encodeUTF8) throws EncodeException

Encodes an array of strings.

endSeqback to summary
public void endSeq() throws EncodeException

Terminate a BER sequence.

ensureFreeBytesback to summary
private void ensureFreeBytes(int len)

Ensures that there are at least "len" unused bytes in "buf". When more space is needed "buf" is expanded by a factor of BUF_GROWTH_FACTOR, then "len" bytes are added if "buf" still isn't large enough.

getBufback to summary
public byte[] getBuf()

Gets the buffer that contains the BER encoding. Throws an exception if unmatched beginSeq() and endSeq() pairs were encountered. Not entire buffer contains encoded bytes. Use getDataLen() to determine number of encoded bytes. Use getBuffer(true) to get rid of excess bytes in array.

Exceptions
IllegalStateException:
If buffer contains unbalanced sequence.
getDataLenback to summary
public int getDataLen()

Gets the number of encoded bytes in this BER buffer.

getTrimmedBufback to summary
public byte[] getTrimmedBuf()

Gets the buffer that contains the BER encoding, trimming unused bytes.

Exceptions
IllegalStateException:
If buffer contains unbalanced sequence.
resetback to summary
public void reset()

Resets encoder to state when newly constructed. Zeros out internal data structures.

shiftSeqDataback to summary
private void shiftSeqData(int start, int len, int shift)

Shifts contents of buf in the range [start,start+len) a specified amount. Positive shift value means shift to the right.