byte
The default byte order of byte buffer is always BIG_ENDIAN.
210211212213214215216217218219220
if (element instanceof PcapPacketImpl) { final PcapPacketImpl p = (PcapPacketImpl) element; final ByteBuffer old = p.getRecordByteBuffer(); if (old.order() == this.editor.order()) { buffer = old.slice(); } else { buffer = PcapRecordIterator.convertByteOrder(BufferUtils.copy(old), this.editor.order());
6465666768697071727374
throw new IllegalArgumentException("Editor is no empty." + " Can only add new block record to completely empty file."); } final ByteBuffer b = ByteBuffer.allocate(PcapBlockRecord.HEADER_LENGTH); b.order(editor.order()); PcapBlockRecordImpl.initBuffer(b); /* * Add our new block record at byte offset 0 to the editor.
116117118119120121122123124125126
return b; } final int length = b.limit() - b.position(); final ByteBuffer r = ByteBuffer.allocate(length); r.order(order); r.putInt(b.getInt()); r.putInt(b.getInt()); r.putInt(b.getInt()); r.putInt(b.getInt());
5758596061626364656667
final int fraction = (int) (millis % 1000); final int micros = fraction * 1000; final ByteBuffer b = ByteBuffer.allocate(PcapPacketRecord.HEADER_LENGTH + included); b.order(editor.order()); PcapPacketRecordImpl.initBuffer(b, included, original, seconds, micros); b.position(PcapPacketRecord.HEADER_LENGTH); b.put(data);
105106107108109110111112113114115
*/ public static ByteBuffer createBuffer(final int length, final ByteOrder order) { final ByteBuffer data = ByteBuffer.allocate(PcapPacketRecord.HEADER_LENGTH + length); data.order(order); final int included = length; final int original = included; final long millis = System.currentTimeMillis(); final long seconds = millis / 1000; final int fraction = (int) (millis % 1000);
633634635636637638639640641642643
/* * Change the byte order in any buffers in the cache as well */ for (int i = 0; i < cache.size(); i++) { final ByteBuffer b = cache.get(i).getByteBuffer(); b.order(order); } } /*
106107108109110111112113114115116
public static long gzipUncompressedSize(File src) throws IOException { FileChannel in = new RandomAccessFile(src, "r").getChannel(); ByteBuffer b = ByteBuffer.allocate(128); b.order(ByteOrder.LITTLE_ENDIAN); in.read(b, in.size() - b.remaining()); final long size = b.getInt(b.limit() - 4);
121122123124125126127128129130131
public static long gzipUncompressedCRC32(File src) throws IOException { FileChannel in = new RandomAccessFile(src, "r").getChannel(); ByteBuffer b = ByteBuffer.allocate(128); b.order(ByteOrder.LITTLE_ENDIAN); in.read(b, in.size() - b.remaining()); final long size = b.getInt(b.limit() - 8);
5051525354555657585960
*/ public static ByteBuffer slice(ByteBuffer buffer) { final ByteOrder o = buffer.order(); final ByteBuffer r = buffer.slice(); r.order(o); return r; } /**
8384858687888990919293
*/ public static ByteBuffer asReadonly(ByteBuffer buffer) { final ByteOrder o = buffer.order(); final ByteBuffer r = buffer.asReadOnlyBuffer(); r.order(o); return r; } public static ByteBuffer copy(ByteBuffer buffer) {