1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.asn1.ber ;
18
19
20 import java.nio.ByteBuffer;
21
22 import org.apache.asn1.codec.DecoderException;
23 import org.apache.asn1.codec.stateful.AbstractStatefulDecoder;
24
25
26 /***
27 * A BER TLV Length component decoder. This decoder delivers a Length instance
28 * to its callback. For efficiency the same Length object is reused. Callback
29 * implementations should not copy the handle to the Length object delivered but
30 * should copy the data if they need it over the long term.
31 *
32 * @author <a href="mailto:dev@directory.apache.org">
33 * Apache Directory Project</a>
34 * @version $Rev: 157644 $
35 */
36 public class LengthDecoder extends AbstractStatefulDecoder
37 {
38 /*** the Length component decoded from a BER TLV Tuple */
39 private final Length length = new Length() ;
40
41
42
43
44
45
46 public void decode( Object encoded ) throws DecoderException
47 {
48 ByteBuffer buf = ( ByteBuffer ) encoded ;
49
50 while ( buf.hasRemaining() )
51 {
52 byte octet = buf.get() ;
53 length.add( octet ) ;
54
55 if ( length.isFixated() )
56 {
57 decodeOccurred( length ) ;
58 length.clear() ;
59 return ;
60 }
61 }
62 }
63 }