1. /*
  2. * @(#)file SnmpOpaque.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 4.8
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. *
  10. */
  11. package com.sun.jmx.snmp;
  12. /**
  13. * Is used to represent an SNMP value.
  14. * The <CODE>Opaque</CODE> type is defined in RFC 1155.
  15. *
  16. * <p><b>This API is a Sun Microsystems internal API and is subject
  17. * to change without notice.</b></p>
  18. * @version 4.8 12/19/03
  19. * @author Sun Microsystems, Inc
  20. */
  21. public class SnmpOpaque extends SnmpString {
  22. // CONSTRUCTORS
  23. //-------------
  24. /**
  25. * Constructs a new <CODE>SnmpOpaque</CODE> from the specified bytes array.
  26. * @param v The bytes composing the opaque value.
  27. */
  28. public SnmpOpaque(byte[] v) {
  29. super(v) ;
  30. }
  31. /**
  32. * Constructs a new <CODE>SnmpOpaque</CODE> with the specified <CODE>Bytes</CODE> array.
  33. * @param v The <CODE>Bytes</CODE> composing the opaque value.
  34. */
  35. public SnmpOpaque(Byte[] v) {
  36. super(v) ;
  37. }
  38. /**
  39. * Constructs a new <CODE>SnmpOpaque</CODE> from the specified <CODE>String</CODE> value.
  40. * @param v The initialization value.
  41. */
  42. public SnmpOpaque(String v) {
  43. super(v) ;
  44. }
  45. // PUBLIC METHODS
  46. //---------------
  47. /**
  48. * Converts the opaque to its <CODE>String</CODE> form, that is, a string of
  49. * bytes expressed in hexadecimal form.
  50. * @return The <CODE>String</CODE> representation of the value.
  51. */
  52. public String toString() {
  53. StringBuffer result = new StringBuffer() ;
  54. for (int i = 0 ; i < value.length ; i++) {
  55. byte b = value[i] ;
  56. int n = (b >= 0) ? b : b + 256 ;
  57. result.append(Character.forDigit(n / 16, 16)) ;
  58. result.append(Character.forDigit(n % 16, 16)) ;
  59. }
  60. return result.toString() ;
  61. }
  62. /**
  63. * Returns a textual description of the type object.
  64. * @return ASN.1 textual description.
  65. */
  66. final public String getTypeName() {
  67. return name ;
  68. }
  69. // VARIABLES
  70. //----------
  71. /**
  72. * Name of the type.
  73. */
  74. final static String name = "Opaque" ;
  75. }