Code example for ByteBuffer

Methods: order

0
	private static int BUFFER_SIZE = BPF_MAXINSNS * 8;
	private final ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
	private int instructionCount;
	 
	public BPFProgram() { 
		buffer.order(ByteOrder.nativeOrder());
	} 
	public void addInstruction(int code, int jt, int jf, int k) {
		buffer.putShort((short) code);
		buffer.put((byte) jt);
		buffer.put((byte) jf);
		buffer.putInt(k);
		instructionCount++;
	} 
	 
	public int getInstructionCount() { 
		return instructionCount;
	} 
	public byte[] getBytes() { 
		int instructionLength = buffer.position();
		byte[] data = new byte[instructionLength];