1 11 12 13 package com.sun.jmx.snmp; 14 15 16 18 import java.lang.Math ; 21 22 32 33 public class SnmpStringFixed extends SnmpString { 34 35 41 public SnmpStringFixed(byte[] v) { 42 super(v) ; 43 } 44 45 49 public SnmpStringFixed(Byte [] v) { 50 super(v) ; 51 } 52 53 57 public SnmpStringFixed(String v) { 58 super(v) ; 59 } 60 61 68 public SnmpStringFixed(int l, byte[] v) throws IllegalArgumentException { 69 if ((l <= 0) || (v == null)) { 70 throw new IllegalArgumentException () ; 71 } 72 int length = Math.min(l, v.length); 73 value = new byte[l] ; 74 for (int i = 0 ; i < length ; i++) { 75 value[i] = v[i] ; 76 } 77 for (int i = length ; i < l ; i++) { 78 value[i] = 0 ; 79 } 80 } 81 82 89 public SnmpStringFixed(int l, Byte [] v) throws IllegalArgumentException { 90 if ((l <= 0) || (v == null)) { 91 throw new IllegalArgumentException () ; 92 } 93 int length = Math.min(l, v.length); 94 value = new byte[l] ; 95 for (int i = 0 ; i < length ; i++) { 96 value[i] = v[i].byteValue() ; 97 } 98 for (int i = length ; i < l ; i++) { 99 value[i] = 0 ; 100 } 101 } 102 103 110 public SnmpStringFixed(int l, String s) throws IllegalArgumentException { 111 if ((l <= 0) || (s == null)) { 112 throw new IllegalArgumentException () ; 113 } 114 byte[] v = s.getBytes(); 115 int length = Math.min(l, v.length); 116 value = new byte[l] ; 117 for (int i = 0 ; i < length ; i++) { 118 value[i] = v[i] ; 119 } 120 for (int i = length ; i < l ; i++) { 121 value[i] = 0 ; 122 } 123 } 124 125 139 public static SnmpOid toOid(int l, long[] index, int start) throws SnmpStatusException { 140 try { 141 long[] ids = new long[l] ; 142 for (int i = 0 ; i < l ; i++) { 143 ids[i] = index[start + i] ; 144 } 145 return new SnmpOid(ids) ; 146 } 147 catch(IndexOutOfBoundsException e) { 148 throw new SnmpStatusException(SnmpStatusException.noSuchName) ; 149 } 150 } 151 152 164 public static int nextOid(int l, long[] index, int start) throws SnmpStatusException { 165 int result = start + l ; 166 if (result > index.length) { 167 throw new SnmpStatusException(SnmpStatusException.noSuchName) ; 168 } 169 return result ; 170 } 171 172 178 public static void appendToOid(int l, SnmpOid source, SnmpOid dest) { 179 dest.append(source) ; 180 } 181 } 182 | Popular Tags |