简体   繁体   中英

Setting Octet string to 0 in Java

i am using the following snmp set command to sent zero values into a hardware.

snmpset -v 3 -u <Username> -a SHA -A "password" -x AES -X "password" -l AuthPriv udp6:[<ipv6>%bond0] <oid> x 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

There are 1024 zeros, now i want to perform the same operation using the code.

But how will i get an octect string with the give values.

I tried using:

final List<Integer> list = new ArrayList<>();
list.add(0);
final OctetString externalVlanIdsBitMapOctetString = BitMapUtils.createLeftBitmap(list);

But i am get snmpset fails with errorCode = 5.

Can anyone help me?

I am not sure whether byte 0, or byte for char '0'. The latter version I commented out.

byte[] bytes = new byte[1024];
//Arrays.fill(bytes, (byte) '0');
final OctetString externalVlanIdsBitMapOctetString = new OctetString(bytes);

如果要创建带有1024个零的字符串:

Sring zeros = String.format("%01024d", 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM