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

SnmpString

public class SnmpString extends SnmpValue
Represents an SNMP string.

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

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

Fields Summary
static final String
name
Name of the type.
protected byte[]
value
This is the bytes array of the string value.
Constructors Summary
public SnmpString()
Constructs a new empty SnmpString.

        value = new byte[0] ;
    
public SnmpString(byte[] v)
Constructs a new SnmpString from the specified bytes array.

param
v The bytes composing the string value.

        value = (byte[])v.clone() ;
    
public SnmpString(Byte[] v)
Constructs a new SnmpString from the specified Bytes array.

param
v The Bytes composing the string value.

        value = new byte[v.length] ;
        for (int i = 0 ; i < v.length ; i++) {
            value[i] = v[i].byteValue() ;
        }
    
public SnmpString(String v)
Constructs a new SnmpString from the specified String value.

param
v The initialization value.

        value = v.getBytes() ;
    
public SnmpString(InetAddress address)
Constructs a new SnmpString from the specified InetAddress .

param
address The InetAddress .
since
1.5

	value = address.getAddress();
    
Methods Summary
public static java.lang.StringBinToChar(java.lang.String bin)
Converts the specified binary string into a character string.

param
bin The binary string value to convert.
return
The character string representation.

        char value[] = new char[bin.length()/8]; 
        int binLength = value.length;
        for (int i = 0; i < binLength; i++) 
            value[i] = (char)Integer.parseInt(bin.substring(8*i, 8*i+8), 2); 
        return new String(value); 
    
public static java.lang.StringHexToChar(java.lang.String hex)
Converts the specified hexadecimal string into a character string.

param
hex The hexadecimal string value to convert.
return
The character string representation.

        char value[] = new char[hex.length()/2]; 
        int hexLength = value.length;
        for (int i = 0; i < hexLength; i++) 
            value[i] = (char)Integer.parseInt(hex.substring(2*i, 2*i+2), 16); 
        return new String(value); 
    
public static voidappendToOid(SnmpOid source, SnmpOid dest)
Appends an SnmpOid representing an SnmpString to another OID.

param
source An OID representing an SnmpString value.
param
dest Where source should be appended.

        dest.append(source.getLength()) ;
        dest.append(source) ;
    
public byte[]byteValue()
Returns the bytes array of this SnmpString.

return
The value.

        return value ;
    
public synchronized java.lang.Objectclone()
Clones the SnmpString object, making a copy of its data.

return
The object clone.

        SnmpString newclone = null ;

        try {
            newclone = (SnmpString) super.clone() ;
            newclone.value = new byte[value.length] ;
            System.arraycopy(value, 0, newclone.value, 0, value.length) ;
        } catch (CloneNotSupportedException e) {
            throw new InternalError() ; // vm bug.
        }
        return newclone ;
    
public final synchronized SnmpValueduplicate()
Performs a clone action. This provides a workaround for the SnmpValue interface.

return
The SnmpValue clone.

        return (SnmpValue) clone() ;
    
public java.lang.StringgetTypeName()
Returns a textual description of the type object.

return
ASN.1 textual description.

        return name ;
    
public java.net.InetAddressinetAddressValue()
Converts the string value to its InetAddress form.

return
an {@link InetAddress} defined by the string value.
exception
UnknownHostException If string value is not a legal address format.
since
1.5

	return InetAddress.getByAddress(value);
    
public static intnextOid(long[] index, int start)
Scans an index OID, skips the string value and returns the position of the next value.

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.

        try {
            if (index[start] > Integer.MAX_VALUE) {
                throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
            }
            int strLen = (int)index[start++] ;
            start += strLen ;
            if (start <= index.length) {
                return start ;
            }
            else {
                throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
            }
        }
        catch(IndexOutOfBoundsException e) {
            throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
        }
    
public java.lang.Byte[]toByte()
Converts the string value to its array of Bytes form.

return
The array of Bytes representation of the value.

        Byte[] result = new Byte[value.length] ;
        for (int i = 0 ; i < value.length ; i++) {
            result[i] = new Byte(value[i]) ;
        }
        return result ;
    
public SnmpOidtoOid()
Converts the string value to its SnmpOid form.

return
The OID representation of the value.

        long[] ids = new long[value.length] ;
        for (int i = 0 ; i < value.length ; i++) {
            ids[i] = (long)(value[i] & 0xFF) ;
        }
        return new SnmpOid(ids) ;
    
public static SnmpOidtoOid(long[] index, int start)
Extracts the string from an index OID and returns its value converted as an SnmpOid.

param
index The index array.
param
start The position in the index array.
return
The OID representing the string value.
exception
SnmpStatusException There is no string value available at the start position.

        try {
            if (index[start] > Integer.MAX_VALUE) {
                throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
            }
            int strLen = (int)index[start++] ;
            long[] ids = new long[strLen] ;
            for (int i = 0 ; i < strLen ; i++) {
                ids[i] = index[start + i] ;
            }
            return new SnmpOid(ids) ;
        }
        catch(IndexOutOfBoundsException e) {
            throw new SnmpStatusException(SnmpStatusException.noSuchName) ;
        }
    
public java.lang.StringtoString()
Converts the string value to its String form.

return
The String representation of the value.

        return new String(value) ;