I have to write an integer in little endian order. So I've created a class (this class does not extend anything) with a FileChannel attribute and some write methods.
But there's a problem: only one method works, the other not!
Here is the working method (dis is the FileChannel):
public void writeBuffer(ByteArrayOutputStream t) throws IOException
{
ByteBuffer buffer=ByteBuffer.wrap(t.toByteArray());
dis.write(buffer);
}
And this is one of the write methods that doesn't work:
public void writeInt(int t) throws IOException
{
ByteBuffer buffer=ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(t);
dis.write(buffer);
}
I debugged the program and dis.write(buffer) returns 0, so what's wrong?
Does anyone know an alternative method for writing 4 byte integers in little endian?