FileDocCategorySizeDatePackage
SnmpStringFixed.javaAPI DocJava SE 5 API6286Fri Aug 26 14:55:04 BST 2005com.sun.jmx.snmp

SnmpStringFixed

public class SnmpStringFixed extends SnmpString
Represents an SNMP String defined with a fixed length. The class is mainly used when dealing with table indexes for which one of the keys is defined as a String.

This API is a Sun Microsystems internal API and is subject to change without notice.

version
4.10 12/19/03
author
Sun Microsystems, Inc

Fields Summary
Constructors Summary
public SnmpStringFixed(byte[] v)
Constructs a new SnmpStringFixed from the specified bytes array.

param
v The bytes composing the fixed-string value.

        super(v) ;
    
public SnmpStringFixed(Byte[] v)
Constructs a new SnmpStringFixed with the specified Bytes array.

param
v The Bytes composing the fixed-string value.

        super(v) ;
    
public SnmpStringFixed(String v)
Constructs a new SnmpStringFixed from the specified String value.

param
v The initialization value.

        super(v) ;
    
public SnmpStringFixed(int l, byte[] v)
Constructs a new SnmpStringFixed from the specified bytes array with the specified length.

param
l The length of the fixed-string.
param
v The bytes composing the fixed-string value.
exception
IllegalArgumentException Either the length or the byte array is not valid.

        if ((l <= 0) || (v == null)) {
            throw new IllegalArgumentException() ;
        }
        int length = Math.min(l, v.length);
        value = new byte[l] ;
        for (int i = 0 ; i < length ; i++) {
            value[i] = v[i] ;
        }
        for (int i = length ; i < l ; i++) {
            value[i] = 0 ;
        }
    
public SnmpStringFixed(int l, Byte[] v)
Constructs a new SnmpStringFixed from the specified Bytes array with the specified length.

param
l The length of the fixed-string.
param
v The Bytes composing the fixed-string value.
exception
IllegalArgumentException Either the length or the Byte array is not valid.

        if ((l <= 0) || (v == null)) {
            throw new IllegalArgumentException() ;
        }
        int length = Math.min(l, v.length);
        value = new byte[l] ;
        for (int i = 0 ; i < length ; i++) {
            value[i] = v[i].byteValue() ;
        }
        for (int i = length ; i < l ; i++) {
            value[i] = 0 ;
        }
    
public SnmpStringFixed(int l, String s)
Constructs a new SnmpStringFixed from the specified String with the specified length.

param
l The length of the fixed-string.
param
s The String composing the fixed-string value.
exception
IllegalArgumentException Either the length or the String is not valid.

        if ((l <= 0) || (s == null)) {
            throw new IllegalArgumentException() ;
        }
        byte[] v = s.getBytes();
        int length = Math.min(l, v.length);
        value = new byte[l] ;
        for (int i = 0 ; i < length ; i++) {
            value[i] = v[i] ;
        }
        for (int i = length ; i < l ; i++) {
            value[i] = 0 ;
        }
    
Methods Summary
public static voidappendToOid(int l, SnmpOid source, SnmpOid dest)
Appends an SnmpOid representing an SnmpStringFixed to another OID.

param
l Unused.
param
source An OID representing an SnmpStringFixed value.
param
dest Where source should be appended.

        dest.append(source) ;
    
public static intnextOid(int l, long[] index, int start)
Scans an index OID, skip the string value and returns the position of the next value.

param
l The number of successive array elements to be passed in order to get the position of the next value. These elements are passed starting at the start position.
param
index The index array.
param
start The position in the index array.
return
The position of the next value.
exception
SnmpStatusException There is no string value available at the start position.

        int result = start + l ;
        if (result > index.length) {
            throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
        }
        return result ;
    
public static SnmpOidtoOid(int l, long[] index, int start)
Extracts the fixed-string from an index OID and returns its value converted as an SnmpOid.

param
l The number of successive array elements to be retreived in order to construct the OID. These elements are retreived starting at the start position.
param
index The index array.
param
start The position in the index array.
return
The OID representing the fixed-string value.
exception
SnmpStatusException There is no string value available at the start position.

        try {
            long[] ids = new long[l] ;
            for (int i = 0 ; i < l ; i++) {
                ids[i] = index[start + i] ;
            }
            return new SnmpOid(ids) ;
        }
        catch(IndexOutOfBoundsException e) {
            throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
        }