com.adventnet.utilities.common
Class CommonUtils

java.lang.Object
  |
  +--com.adventnet.utilities.common.CommonUtils

public class CommonUtils
extends java.lang.Object

This class contains the Utility Methods which can be used for both Snmp and JMX agents.


Field Summary
static int _CLASS
          Constant for CLASS-COMMAND
static int _CORBA
          Constant for CORBA-COMMAND
static int _DATABASE
          Constant for DATABASE-COMMAND
static int _FILE
          Constant for FILE-COMMAND
static int _PROXY
          Constant for PROXY-COMMAND
static int _READ
          Constant for READ-COMMAND
static int _SIMULATE
          Constant for SIMULATE-COMMAND
static int _WRITE
          Constant for WRITE-COMMAND
static byte AUTHORIZATIONERROR
          SNMP error value for Authorization Failure.
static byte BADVALUE
          SNMP error value for Bad Values.
static byte COMMITFAILED
          SNMP error value for Commit Failure.
(package private) static boolean DEBUG
           
static byte GENERR
          SNMP error value for General Errors.
static byte INCONSISTENTNAME
          SNMP error value for Inconsistent Names.
static byte INCONSISTENTVALUE
          SNMP error value for Inconsistent Values.
static byte INVALIDEXTERNALINDEX
          Table error value if the External Index is not Valid.
static byte INVALIDINDEX
          Table error value if the Index is not a Valid one.
static byte MODIFYROWNOTEXIST
          Table error value if Modiry Row does not exist.
static byte NOACCESS
          SNMP error value if it is Not Accessible.
static byte NOCREATION
          SNMP error value for NoCreation.
static byte NOERROR
          SNMP error value for No Error.
static byte NOSUCHNAME
          SNMP error value for No Such Name.
static byte NOTWRITABLE
          SNMP error value if it is Not Writable.
static byte READONLY
          SNMP error value for Read Only access.
static byte RESOURCEUNAVAILABLE
          SNMP error value if the Resource is not available.
static byte ROWCREATIONFAILED
          Table error value if Row Creation has been failed.
(package private) static boolean setupStdOutErrDone
          variable having debugLevel , by defaullt FATAL.
static byte TOOBIG
          SNMP error value for Too Big.
static byte UNDOFAILED
          SNMP error value for Undo Failure.
static byte WRONGENCODING
          SNMP error value for Wrong Encoding.
static byte WRONGLENGTH
          SNMP error value if the value given is of Wrong Length.
static byte WRONGTYPE
          SNMP error value if the value given is of Wrong Type.
static byte WRONGVALUE
          SNMP error value for Wrong Values given.
 
Constructor Summary
CommonUtils()
          Default Constructor.
 
Method Summary
static java.lang.String changeToSystemURL(java.lang.String myString)
          Utility method to convert the filePath String with file separators to String with System based File separator
static boolean checkFilePerms(java.lang.String fileName, java.lang.String access)
          The Method for cheching the access Permission of a specified File.
static int compareToMinSize(int[] oid_1, int[] oid_2)
           
static byte[] convertBinaryIntArrayToByteArray(int[] intArray)
          Converting Binary Integer Array to Byte Array.
static int[] convertByteArrayToBinaryIntArray(byte[] byteArray, int intArrayLength)
          Converting Byte Array to Binary Integer Array.
static java.lang.Byte[] convertbyteArrayToByteArray(byte[] byteObj)
           
static byte[] convertByteArrayTobyteArray(java.lang.Byte[] byteObj)
          Converts the Byte array to byte Array.
static java.lang.String convertCharacterToString(java.lang.Character charIn)
           
static int[] convertHexaToIntArray(java.lang.String str, int len)
          Method to convert Hexa to Int Array.
static java.lang.String convertIntegerArrayToHexa(int[] intArr)
          To convert Integer Array to Hexa value.
static int[] convertIntToIntArray(int val)
          This method Converts Integer to Integer Array.
static java.lang.Character convertStringToCharacter(java.lang.String charIn)
           
static java.lang.String dateString(byte[] datearray)
          Converts the byte[] values to String representing the Date and Time.
static byte[] dateStringToByteArray(java.lang.String dateStr)
          Converts the String representing the date and time value to byte Array.
static int get_input(java.lang.String mesg)
           
static java.lang.Object getAgentReference()
          Getter for Agent Reference Object .
static boolean getDebug()
          gets debug flag.
static int getMinSize(int[] oid_1, int[] oid_2)
           
static java.lang.String getReadCommandString(java.lang.String command_string, java.lang.String defaultValue)
          getter for Read command String.
static java.lang.String intArrayToString(int[] longarray)
          converts int array to string OID.
static void print(java.lang.Object str)
          Print to stdout
static void println(java.lang.Object str)
          Print line to stdout
static void setAgentReference(java.lang.Object obj)
          Setter for Agent Reference Object.
static void setDebug(boolean val)
           
static void setupStdOutErr()
          makes logs directory for stdout and stderr files
static void setupStdOutErr(java.lang.String dirStr)
          makes specified directory for stdout and stderr files
static void setupStdOutErr(java.lang.String dirStr, java.lang.String oFileName, java.lang.String eFileName)
          Makes the specified directory and writes the outputs and errors to the specified fileNames.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOERROR

public static final byte NOERROR
SNMP error value for No Error.

TOOBIG

public static final byte TOOBIG
SNMP error value for Too Big.

NOSUCHNAME

public static final byte NOSUCHNAME
SNMP error value for No Such Name.

BADVALUE

public static final byte BADVALUE
SNMP error value for Bad Values.

READONLY

public static final byte READONLY
SNMP error value for Read Only access.

GENERR

public static final byte GENERR
SNMP error value for General Errors.

NOACCESS

public static final byte NOACCESS
SNMP error value if it is Not Accessible.

WRONGTYPE

public static final byte WRONGTYPE
SNMP error value if the value given is of Wrong Type.

WRONGLENGTH

public static final byte WRONGLENGTH
SNMP error value if the value given is of Wrong Length.

WRONGENCODING

public static final byte WRONGENCODING
SNMP error value for Wrong Encoding.

WRONGVALUE

public static final byte WRONGVALUE
SNMP error value for Wrong Values given.

NOCREATION

public static final byte NOCREATION
SNMP error value for NoCreation.

INCONSISTENTVALUE

public static final byte INCONSISTENTVALUE
SNMP error value for Inconsistent Values.

RESOURCEUNAVAILABLE

public static final byte RESOURCEUNAVAILABLE
SNMP error value if the Resource is not available.

COMMITFAILED

public static final byte COMMITFAILED
SNMP error value for Commit Failure.

UNDOFAILED

public static final byte UNDOFAILED
SNMP error value for Undo Failure.

AUTHORIZATIONERROR

public static final byte AUTHORIZATIONERROR
SNMP error value for Authorization Failure.

NOTWRITABLE

public static final byte NOTWRITABLE
SNMP error value if it is Not Writable.

INCONSISTENTNAME

public static final byte INCONSISTENTNAME
SNMP error value for Inconsistent Names.

MODIFYROWNOTEXIST

public static final byte MODIFYROWNOTEXIST
Table error value if Modiry Row does not exist.

ROWCREATIONFAILED

public static final byte ROWCREATIONFAILED
Table error value if Row Creation has been failed.

INVALIDEXTERNALINDEX

public static final byte INVALIDEXTERNALINDEX
Table error value if the External Index is not Valid.

INVALIDINDEX

public static final byte INVALIDINDEX
Table error value if the Index is not a Valid one.

_READ

public static final int _READ
Constant for READ-COMMAND

_WRITE

public static final int _WRITE
Constant for WRITE-COMMAND

_FILE

public static final int _FILE
Constant for FILE-COMMAND

_CLASS

public static final int _CLASS
Constant for CLASS-COMMAND

_PROXY

public static final int _PROXY
Constant for PROXY-COMMAND

_SIMULATE

public static final int _SIMULATE
Constant for SIMULATE-COMMAND

_DATABASE

public static final int _DATABASE
Constant for DATABASE-COMMAND

_CORBA

public static final int _CORBA
Constant for CORBA-COMMAND

DEBUG

static boolean DEBUG

setupStdOutErrDone

static boolean setupStdOutErrDone
variable having debugLevel , by defaullt FATAL.
Constructor Detail

CommonUtils

public CommonUtils()
Default Constructor.
Method Detail

setDebug

public static void setDebug(boolean val)

getDebug

public static boolean getDebug()
gets debug flag.
See Also:
setDebug(boolean val).

convertByteArrayToBinaryIntArray

public static int[] convertByteArrayToBinaryIntArray(byte[] byteArray,
                                                     int intArrayLength)
Converting Byte Array to Binary Integer Array.
Parameters:
byteArray - The array of bytes to be converted as Binary int array
intArrayLength - The resultant integer.
Returns:
The converted Integer Array.

convertBinaryIntArrayToByteArray

public static byte[] convertBinaryIntArrayToByteArray(int[] intArray)
Converting Binary Integer Array to Byte Array.
Parameters:
intArray - The Binary Integer Array to be converted.
Returns:
The converted Byte Array.

convertIntToIntArray

public static int[] convertIntToIntArray(int val)
This method Converts Integer to Integer Array.
Parameters:
val - The Integer value for conversion.
Returns:
The resultant Int Array.

convertHexaToIntArray

public static int[] convertHexaToIntArray(java.lang.String str,
                                          int len)
Method to convert Hexa to Int Array.
Parameters:
str - The String Value.
len - The Length of the string.
Returns:
The rtesultant Integer Array.

convertIntegerArrayToHexa

public static java.lang.String convertIntegerArrayToHexa(int[] intArr)
To convert Integer Array to Hexa value.
Parameters:
intArr - The input Integer Array.
Returns:
The equivalent Hexa value.

get_input

public static int get_input(java.lang.String mesg)

dateString

public static java.lang.String dateString(byte[] datearray)
                                   throws java.lang.Exception
Converts the byte[] values to String representing the Date and Time.
Parameters:
datearray - the array of bytes to be returned as a String representing the Date and Time.The length of the array should be 8 or 11
Returns:
The Date and Time String.
Throws:
java.lang.Exception - when forming the String with the given values fails.

convertByteArrayTobyteArray

public static byte[] convertByteArrayTobyteArray(java.lang.Byte[] byteObj)
                                          throws java.lang.Exception
Converts the Byte array to byte Array.
Parameters:
byteObj - converted to the byte[].
Returns:
The equivalent Byte Array.
Throws:
java.lang.Exception - when forming the byte array with the given values fails.

convertbyteArrayToByteArray

public static java.lang.Byte[] convertbyteArrayToByteArray(byte[] byteObj)
                                                    throws java.lang.Exception

convertStringToCharacter

public static java.lang.Character convertStringToCharacter(java.lang.String charIn)
                                                    throws java.lang.Exception

convertCharacterToString

public static java.lang.String convertCharacterToString(java.lang.Character charIn)
                                                 throws java.lang.Exception

dateStringToByteArray

public static byte[] dateStringToByteArray(java.lang.String dateStr)
                                    throws java.lang.Exception
Converts the String representing the date and time value to byte Array.
Parameters:
dateStr - the String representing the Date and Time that is to be converted to the byte[].
Returns:
The equivalent Byte Array.
Throws:
java.lang.Exception - when forming the byte array with the given values fails.

checkFilePerms

public static boolean checkFilePerms(java.lang.String fileName,
                                     java.lang.String access)
The Method for cheching the access Permission of a specified File.
Parameters:
fileName - The File Name to be checked.
access - The access value looking for.
Returns:
True if the File is accessible else False.

getReadCommandString

public static java.lang.String getReadCommandString(java.lang.String command_string,
                                                    java.lang.String defaultValue)
getter for Read command String. Default arguments of Read command is replaced with proper arguments.
Parameters:
command_string - the command to be executed eg. netstat $value
defaultValue - the options for the command eg. -an
Returns:
String eg. netstat -an will be returned.

setAgentReference

public static void setAgentReference(java.lang.Object obj)
Setter for Agent Reference Object.
Parameters:
obj - the main file reference.

getAgentReference

public static java.lang.Object getAgentReference()
Getter for Agent Reference Object . This is useful for getting the reference of the Main file generated. MBeans can get the reference of the main file to access data available through Main file.
Returns:
The Object Reference.

print

public static void print(java.lang.Object str)
Print to stdout
See Also:
println(Object str), printErr(Object str), printlnErr(Object str)

println

public static void println(java.lang.Object str)
Print line to stdout
See Also:
print(Object str), printErr(Object str), printlnErr(Object str)

changeToSystemURL

public static java.lang.String changeToSystemURL(java.lang.String myString)
Utility method to convert the filePath String with file separators to String with System based File separator
Parameters:
myString - The string to be converted to system based File path
Returns:
The String with replaced File separators to system based File separators

intArrayToString

public static java.lang.String intArrayToString(int[] longarray)
converts int array to string OID.

setupStdOutErr

public static void setupStdOutErr()
makes logs directory for stdout and stderr files
See Also:
setupStdOutErr(String dirStr), setupStdOutErr(String dirStr, String oFileName, String eFileName), setupStdOutErr(OutputStream outputStream)

setupStdOutErr

public static void setupStdOutErr(java.lang.String dirStr)
makes specified directory for stdout and stderr files
Parameters:
dirStr - The directory to which the files are to be created
See Also:
setupStdOutErr(), setupStdOutErr(String dirStr, String oFileName, String eFileName), setupStdOutErr(OutputStream outputStream)

setupStdOutErr

public static void setupStdOutErr(java.lang.String dirStr,
                                  java.lang.String oFileName,
                                  java.lang.String eFileName)
Makes the specified directory and writes the outputs and errors to the specified fileNames.
Parameters:
dirStr - The directory in which to create the files
oFileName - The outputs fileName
eFileName - The errors fileName
See Also:
setupStdOutErr(), setupStdOutErr(String dirStr), setupStdOutErr(OutputStream outputStream)

compareToMinSize

public static int compareToMinSize(int[] oid_1,
                                   int[] oid_2)

getMinSize

public static int getMinSize(int[] oid_1,
                             int[] oid_2)