java - MappedbyteBuffer.get() increments position by too much -
the relevant part of file this:
82 0a 96 c9 82 0a 96 d3 00 66 13 08 i open file in mappedbytebuffer , set position beginning. this:
mappedbytebuffer buffer = channel.map(filechannel.mapmode.read_only, 0, channel.size()); ... buffer.position(packetinfos.get(idpacket).getstartpos()); //getting time packet header time = math.addexact(math.multiplyexact((long) buffer.order(byteorder.little_endian).getint(), 1000), math.floordiv(buffer.order(byteorder.little_endian).getint(), 1000)); //getting source ip ip frame buffer.position(packetinfos.get(idpacket).getstartpos() + packet_ipsource_offs); // puts buffers position @ part of file shown above source = bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()); //getting destination ip ip frame destination = bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()); the bytetounsigned method does:
public static int bytetounsigned(byte b){ return b & 0xff; } source ends being: "130.10.150.211" when should "130.10.150.201". reason get() method increments position of buffer 1 in cases, 5 after third time? might have guessed i'm trying decode destination ip afterwards , starts reading after "d3", resulting in "0.102.19.8"
even before bytetounsigned calls source ip "-126.10.-106.-45".
after debugging step step through line:
source = bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()) + "." + bytetounsigned(buffer.get()); watching buffer.position() , buffer.get(), see following:
- first get(): buffer.position()=70, buffer.get()=-126
- second get(): buffer.position()=71, buffer.get()=10
- third get(): buffer.position()=72, buffer.get()=-106
- fourth get(): buffer.position()=73, buffer.get()=-45
so position incremented correctly, bytes between 72nd , 77th not visible buffer somehow?
the api plainly states:
public abstract byte get() relative method. reads byte @ buffer's current position, , increments position. what missing?
turns out i'm enormous idiot. did not notice bytes 82 0a 96 repeat few bytes right. accidentally placed position of buffer. don't worry, i'm ashamed.
Comments
Post a Comment