First, you seem to assume that the int is big endian. Well, this is Java so it will certainly be the case.
Second, your error is expected: an int is 4 bytes.
Since you want the two last bytes, you can do that without having to go through a byte buffer:
public static byte[] toBytes(final int counter)
{
final byte[] ret = new byte[2];
ret[0] = (byte) ((counter & 0xff00) >> 8);
ret[1] = (byte) (counter & 0xff);
return ret;
}
You could also use a ByteBuffer, of course:
public static byte[] toBytes(final int counter)
{
// Integer.BYTES is there since Java 8
final ByteBuffer buf = ByteBuffer.allocate(Integer.BYTES);
buf.put(counter);
final byte[] ret = new byte[2];
// Skip the first two bytes, then put into the array
buf.position(2);
buf.put(ret);
return ret;
}