01: /*_############################################################################
02: _##
03: _## SNMP4J - Opaque.java
04: _##
05: _## Copyright (C) 2003-2008 Frank Fock and Jochen Katz (SNMP4J.org)
06: _##
07: _## Licensed under the Apache License, Version 2.0 (the "License");
08: _## you may not use this file except in compliance with the License.
09: _## 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: package org.snmp4j.smi;
22:
23: import java.io.*;
24: import org.snmp4j.asn1.BER;
25: import org.snmp4j.asn1.BERInputStream;
26:
27: /**
28: * The <code>Opaque</code> class represents the SMI type Opaque which is used
29: * to transparently exchange BER encoded values.
30: *
31: * @author Frank Fock
32: * @version 1.7.6
33: */
34: public class Opaque extends OctetString {
35:
36: private static final long serialVersionUID = -17056771587100877L;
37:
38: public Opaque() {
39: super ();
40: }
41:
42: public Opaque(byte[] bytes) {
43: super (bytes);
44: }
45:
46: public int getSyntax() {
47: return SMIConstants.SYNTAX_OPAQUE;
48: }
49:
50: public void encodeBER(OutputStream outputStream) throws IOException {
51: BER.encodeString(outputStream, BER.OPAQUE, getValue());
52: }
53:
54: public void decodeBER(BERInputStream inputStream)
55: throws IOException {
56: BER.MutableByte type = new BER.MutableByte();
57: byte[] v = BER.decodeString(inputStream, type);
58: if (type.getValue() != (BER.ASN_APPLICATION | 0x04)) {
59: throw new IOException(
60: "Wrong type encountered when decoding OctetString: "
61: + type.getValue());
62: }
63: setValue(v);
64: }
65:
66: public void setValue(OctetString value) {
67: this .setValue(new byte[0]);
68: append(value);
69: }
70:
71: public String toString() {
72: return super .toHexString();
73: }
74:
75: public Object clone() {
76: return new Opaque(super.getValue());
77: }
78:
79: }
|