The following is the code:
byte[] topo1={2,1,1,6,6};
byte[] topo2={2,1,1,2,2};
byte[] topo3={2,5,5,4,4};
byte[] topo4={2,3,3,5,5};
byte[] topo5={2,4,4,3,3};
byte[][] topology = {topo1,topo2,topo3,topo4,topo5};
writeToLog(String.format("%s receives INIT from nse", routerName));
writeToLog(" ");
parseCircuitDB(topology[routerId-1]);
This the parseCircuitDB method where it shows the error:
private void parseCircuitDB(byte[] string) throws Exception {
ByteBuffer buffer = ByteBuffer.wrap(string);
buffer.order(ByteOrder.LITTLE_ENDIAN);
//gettign the number of neighbor links
nbrLink = buffer.getInt();
System.out.println(nbrLink);
logMsg = String.format("%d neighbor links exist", nbrLink);
writeToLog(logMsg);
for( int i = 1; i <= nbrLink; i++ ) {
//link id as integer
int l = buffer.getInt();
System.out.println(l);
//link cost as integer
int c = buffer.getInt();
link_cost a = new link_cost(l, c);
topo_db[routerId].linkCost.put(l, a);
}
}
I get the error BufferUnderflowException. I tried checking the loops but i dont see any problem there.