82
83 /**
84 * Gets the number of encoded bytes in this BER buffer.
85 */
86 public int getDataLen() {
87 return offset;
88 }
89
90 /**
91 * Gets the buffer that contains the BER encoding. Throws an
92 * exception if unmatched beginSeq() and endSeq() pairs were
93 * encountered. Not entire buffer contains encoded bytes.
94 * Use getDataLen() to determine number of encoded bytes.
95 * Use getBuffer(true) to get rid of excess bytes in array.
96 * @throws IllegalStateException If buffer contains unbalanced sequence.
97 */
98 public byte[] getBuf() {
99 if (curSeqIndex != 0) {
100 throw new IllegalStateException("BER encode error: Unbalanced SEQUENCEs.");
101 }
102 return buf;
103 }
104
105 /**
106 * Gets the buffer that contains the BER encoding, trimming unused bytes.
107 *
108 * @throws IllegalStateException If buffer contains unbalanced sequence.
109 */
110 public byte[] getTrimmedBuf() {
111 int len = getDataLen();
112 byte[] trimBuf = new byte[len];
113
114 System.arraycopy(getBuf(), 0, trimBuf, 0, len);
115 return trimBuf;
116 }
117
118 // -------------- encoding methods -------------
119
120 /**
121 * Begin encoding a sequence with a tag.
122 */
|
82
83 /**
84 * Gets the number of encoded bytes in this BER buffer.
85 */
86 public int getDataLen() {
87 return offset;
88 }
89
90 /**
91 * Gets the buffer that contains the BER encoding. Throws an
92 * exception if unmatched beginSeq() and endSeq() pairs were
93 * encountered. Not entire buffer contains encoded bytes.
94 * Use getDataLen() to determine number of encoded bytes.
95 * Use getBuffer(true) to get rid of excess bytes in array.
96 * @throws IllegalStateException If buffer contains unbalanced sequence.
97 */
98 public byte[] getBuf() {
99 if (curSeqIndex != 0) {
100 throw new IllegalStateException("BER encode error: Unbalanced SEQUENCEs.");
101 }
102 return buf; // shared buffer, be careful to use this method.
103 }
104
105 /**
106 * Gets the buffer that contains the BER encoding, trimming unused bytes.
107 *
108 * @throws IllegalStateException If buffer contains unbalanced sequence.
109 */
110 public byte[] getTrimmedBuf() {
111 int len = getDataLen();
112 byte[] trimBuf = new byte[len];
113
114 System.arraycopy(getBuf(), 0, trimBuf, 0, len);
115 return trimBuf;
116 }
117
118 // -------------- encoding methods -------------
119
120 /**
121 * Begin encoding a sequence with a tag.
122 */
|