KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > SnmpOpaque


1 /*
2  * @(#)file SnmpOpaque.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.8
5  * @(#)date 08/02/09
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  *
10  */

11
12
13 package com.sun.jmx.snmp;
14
15
16
17 /**
18  * Is used to represent an SNMP value.
19  * The <CODE>Opaque</CODE> type is defined in RFC 1155.
20  *
21  * <p><b>This API is a Sun Microsystems internal API and is subject
22  * to change without notice.</b></p>
23  * @version 4.8 12/19/03
24  * @author Sun Microsystems, Inc
25  */

26
27 public class SnmpOpaque extends SnmpString {
28
29     // CONSTRUCTORS
30
//-------------
31
/**
32      * Constructs a new <CODE>SnmpOpaque</CODE> from the specified bytes array.
33      * @param v The bytes composing the opaque value.
34      */

35     public SnmpOpaque(byte[] v) {
36     super(v) ;
37     }
38
39     /**
40      * Constructs a new <CODE>SnmpOpaque</CODE> with the specified <CODE>Bytes</CODE> array.
41      * @param v The <CODE>Bytes</CODE> composing the opaque value.
42      */

43     public SnmpOpaque(Byte JavaDoc[] v) {
44     super(v) ;
45     }
46
47     /**
48      * Constructs a new <CODE>SnmpOpaque</CODE> from the specified <CODE>String</CODE> value.
49      * @param v The initialization value.
50      */

51     public SnmpOpaque(String JavaDoc v) {
52     super(v) ;
53     }
54
55     // PUBLIC METHODS
56
//---------------
57
/**
58      * Converts the opaque to its <CODE>String</CODE> form, that is, a string of
59      * bytes expressed in hexadecimal form.
60      * @return The <CODE>String</CODE> representation of the value.
61      */

62     public String JavaDoc toString() {
63     StringBuffer JavaDoc result = new StringBuffer JavaDoc() ;
64     for (int i = 0 ; i < value.length ; i++) {
65         byte b = value[i] ;
66         int n = (b >= 0) ? b : b + 256 ;
67         result.append(Character.forDigit(n / 16, 16)) ;
68         result.append(Character.forDigit(n % 16, 16)) ;
69     }
70     return result.toString() ;
71     }
72
73     /**
74      * Returns a textual description of the type object.
75      * @return ASN.1 textual description.
76      */

77     final public String JavaDoc getTypeName() {
78         return name ;
79     }
80
81     // VARIABLES
82
//----------
83
/**
84      * Name of the type.
85      */

86     final static String JavaDoc name = "Opaque" ;
87 }
88
Popular Tags