Code example for ByteBuffer

Methods: put, putInt, putShort

0
	 
	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];
		System.arraycopy(buffer.array(), 0, data, 0, instructionLength);
		return data;
	}