[SNMP4J] Going from BER Input Stream to OID String

Garcia, Maurice Maurice_Garcia at Cable.Comcast.com
Tue Oct 15 19:36:36 CEST 2013


Excellent!!!!! That worked!

Thank You!!!!

-----Original Message-----
From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org] On Behalf Of Frank Fock
Sent: Tuesday, October 15, 2013 1:18 PM
To: snmp4j at agentpp.org
Subject: Re: [SNMP4J] Going from BER Input Stream to OID String

Hi,

I am not sure, but I thiunk you need to rewind the input ByteBuffer to position 0 before you can decode after the put.

Best regards,
Frank

Am 15.10.2013 19:12, schrieb Garcia, Maurice:
> 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:
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

--
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231

_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j



More information about the SNMP4J mailing list