KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > smi > Opaque


1 /*_############################################################################
2   _##
3   _## SNMP4J - Opaque.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22
23
24
25 package org.snmp4j.smi;
26
27 import java.io.*;
28 import org.snmp4j.asn1.BER;
29 import org.snmp4j.asn1.BERInputStream;
30
31 /**
32  * The <code>Opaque</code> class represents the SMI type Opaque which is used
33  * to transparently exchange BER encoded values.
34  *
35  * @author Frank Fock
36  * @version 1.7.6
37  */

38 public class Opaque extends OctetString {
39
40   private static final long serialVersionUID = -17056771587100877L;
41
42   public Opaque() {
43     super();
44   }
45
46   public Opaque(byte[] bytes) {
47     super(bytes);
48   }
49
50   public int getSyntax() {
51     return SMIConstants.SYNTAX_OPAQUE;
52   }
53
54   public void encodeBER(OutputStream outputStream) throws IOException {
55     BER.encodeString(outputStream, BER.OPAQUE, getValue());
56   }
57
58   public void decodeBER(BERInputStream inputStream) throws IOException {
59     BER.MutableByte type = new BER.MutableByte();
60     byte[] v = BER.decodeString(inputStream, type);
61     if (type.getValue() != (BER.ASN_APPLICATION | 0x04)) {
62       throw new IOException("Wrong type encountered when decoding OctetString: "+
63                             type.getValue());
64     }
65     setValue(v);
66   }
67
68   public void setValue(OctetString value) {
69     this.setValue(new byte[0]);
70     append(value);
71   }
72
73   public String JavaDoc toString() {
74     return super.toHexString();
75   }
76
77   public Object JavaDoc clone() {
78     return new Opaque(super.getValue());
79   }
80
81 }
82
83
Popular Tags