I am trying to write a method that takes a byte array as an input, appends a 3-byte header onto the array and sends the resulting byte array to a remote host via an OutputStream.
My method signature is something like this:
public void write(byte[] data)
{
byte [] packet = new byte[data.length + 3];
packet = System.arraycopy(data,0,header,header.length)
packet[0] = 3; //<--- I just need to encode the integer 3
packet[1] = 0;
packet[2] = packet.length;<---I need to encode the
length of the packet here
}
My problem is that I don't know how to encode the integer values into the bytes. And I'm not sure if the arraycopy will work correctly.
Can anyone advise me on this?
Thanks,
Gregory A. Lusk, P.E., CCNA
My method signature is something like this:
public void write(byte[] data)
{
byte [] packet = new byte[data.length + 3];
packet = System.arraycopy(data,0,header,header.length)
packet[0] = 3; //<--- I just need to encode the integer 3
packet[1] = 0;
packet[2] = packet.length;<---I need to encode the
length of the packet here
}
My problem is that I don't know how to encode the integer values into the bytes. And I'm not sure if the arraycopy will work correctly.
Can anyone advise me on this?
Thanks,
Gregory A. Lusk, P.E., CCNA