1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 Tag component decoder. This decoder delivers a Tag instance
28 * to its callback. For efficiency the same Tag object is reused. Callback
29 * implementations should not copy the handle to the Tag object delivered but
30 * should copy the data if they need it over the long term.
31 *
32 *
33 * @author <a href="mailto:dev@directory.apache.org">
34 * Apache Directory Project</a>
35 * @version $Rev: 157644 $
36 */
37 public class TagDecoder extends AbstractStatefulDecoder
38 {
39 private final Tag tag = new Tag() ;
40
41
42 /* (non-Javadoc)
43 * @see org.apache.asn1.codec.stateful.StatefulDecoder#decode(
44 * java.lang.Object)
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 tag.add( octet ) ;
54
55 if ( tag.isFixated() )
56 {
57 decodeOccurred( tag ) ;
58 tag.clear() ;
59 return ;
60 }
61 }
62 }
63 }