[SNMP4J] Going from BER Input Stream to OID String
Garcia, Maurice
Maurice_Garcia at Cable.Comcast.com
Tue Oct 15 19:12:34 CEST 2013
Hi All,
I've been working with SNMP4J for a couple of weeks adding it to a project that I am working on.
I am using SNMP4J for OID -> BER and vice-versa.
In the below example, I am trying to from BER -> OID, but I am getting an error.
I am not seeing where I am going wrong??? It is expecting more, but I am using a direct conversion from oOID.encodeBER(), so I am not sure what more it is expecting?
Help Please!!!
CODE:
String sSnmpOID = "1.3.6.1.2.1.4115.10.1.14.0";
System.out.println("PRE-OID-DOT-NOTATION: " + sSnmpOID);
OID oOID = new OID(sSnmpOID);
ByteArrayOutputStream baosBER = new ByteArrayOutputStream();
try {
oOID.encodeBER(baosBER);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//This only displays what is contained in ByteArrayOutputStream
System.out.println("baosBER: " + new HexString(baosBER.toByteArray()).toString());
//Convert to ByteBuffer
ByteBuffer bbBER = ByteBuffer.allocate(baosBER.size());
//Add byte Array
bbBER.put(baosBER.toByteArray());
//Create BERInputStream from ByteBuffer BER
BERInputStream bisOID = new BERInputStream(bbBER);
//Create OID Object
OID oOIDNew = new OID();
try {
oOIDNew.decodeBER(bisOID);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("PST-OID-DOT-NOTATION: " + oOIDNew.toDottedString());
OUTPUT:
PRE-OID-DOT-NOTATION: 1.3.6.1.2.1.4115.10.1.14.0
baosBER: 06 0B 2B 06 01 02 01 A0 13 0A 01 0E 00
java.io.IOException: Unexpected end of input stream at position 13
at org.snmp4j.asn1.BERInputStream.read(BERInputStream.java:58)
at org.snmp4j.asn1.BER.decodeOID(BER.java:738)
at org.snmp4j.smi.OID.decodeBER(OID.java:302)
at BERTest.main(BERTest.java:119)
PST-OID-DOT-NOTATION:
More information about the SNMP4J
mailing list