byte
The default byte order of byte buffer is always BIG_ENDIAN.
93949596979899100101102103
public static ByteBuffer copy(ByteBuffer buffer) { final int length = buffer.limit() - buffer.position(); final ByteOrder o = buffer.order(); final ByteBuffer r = ByteBuffer.allocate(length); r.order(o); r.put(buffer); r.clear(); // Reset position and limit after the put() return r;
183184185186187188189190191192
* @param buffer * @return */ public static ByteBuffer duplicate(ByteBuffer buffer) { final ByteBuffer r = buffer.duplicate(); r.order(buffer.order()); return r; } }
6364656667686970717273
public static ByteBuffer createBuffer(final int length) { final ByteBuffer data = ByteBuffer.allocate(SnoopPacketRecord.HEADER_LENGTH + length); data.order(ByteOrder.BIG_ENDIAN); final int included = length; final int original = included; final int record = included + SnoopPacketRecord.HEADER_LENGTH; final int drops = 0; final long millis = System.currentTimeMillis();
6263646566676869707172
throw new IllegalArgumentException("Editor is no empty." + " Can only add new block record to completely empty file."); } final ByteBuffer b = ByteBuffer.allocate(SnoopBlockRecord.HEADER_LENGTH); b.order(editor.order()); SnoopBlockRecordImpl.initBuffer(b); /* * Add our new block record at byte offset 0 to the editor.
133134135136137138139140141142143
final long original, final long seconds, final long nanos) throws IOException { final int included = data.limit() - data.position(); final int length = included + SnoopPacketRecord.HEADER_LENGTH; final ByteBuffer record = ByteBuffer.allocate(length); record.order(this.editor.order()); PcapPacketRecordImpl.initBuffer(record, included, (int) original, seconds, (int) nanos / 1000); /*
214215216217218219220221222223224
if (element instanceof SnoopPacketImpl) { final AFilePacket p = (AFilePacket) element; final ByteBuffer old = p.getRecordByteBuffer(); if (old.order() == this.editor.order()) { buffer = BufferUtils.slice(old); } else { throw new IllegalArgumentException( "Supplied packet buffer is not in BIG_ENDIAN order. " + "Snoop supports only BIG_ENDIAN.");
115116117118119120121122123124125
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());
183184185186187188189190191192193
return 0; } public static ByteBuffer getByteBuffer(long bufferSize) { ByteBuffer data = ByteBuffer.allocate(8); data.order(ByteOrder.LITTLE_ENDIAN); data.putLong(bufferSize); return ByteBuffer.allocate(data.getInt(0)).order( ByteOrder.LITTLE_ENDIAN); }
368369370371372373374375376377378
String[] result = new String[size]; for (int i = 0; i < size; i++) result[i] = headerParser.readHeapString(bb, destPos + i * 16); // 16 byte "heap ids" are in the ByteBuffer int index = asbb.addObjectToHeap(result); bb.order(ByteOrder.nativeOrder()); // the string index is always written in "native order" bb.putInt(destPos, index); // overwrite with the index into the StringHeap } } }
197198199200201202203204205206207
} else throw new RuntimeException("Unknown filter type="+f.id); } ByteBuffer result = ByteBuffer.wrap(data); result.order(byteOrder); return result; } /** * inflate data