I just checked, using ObjectOutputStream will not work to write a RAW file.
There’s something below that should work for you for writing an array of ints. Written for clarity: I’m not claiming it’s the bestest & fastest way but it should work fine and it should illustrate endianness. Check the output in a hex editor:
...
// does not work, will have a header:
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("oos.obj")));
oos.writeInt(1);
oos.writeInt(2);
oos.writeInt(3);
oos.writeInt(4);
oos.close();
// below works:
FileOutputStream fos;
int[] i = {1,2,3,4};
// 32bit little endian:
fos = new FileOutputStream(new File("myints32le.dat"));
writeLE(i, fos);
fos.close();
// 32bit big endian:
fos = new FileOutputStream(new File("myints32be.dat"));
writeBE(i, fos);
fos.close();
// 16bit little endian:
fos = new FileOutputStream(new File("myints16le.dat"));
writeLE16(i, fos);
fos.close();
// 16bit big endian:
fos = new FileOutputStream(new File("myints16be.dat"));
writeBE16(i, fos);
fos.close();
...
private void writeLE(int[] values, OutputStream os) throws IOException {
for (int i : values) {
os.write(i & 0xff);
os.write((i >> 8) & 0xff);
os.write((i >> 16) & 0xff);
os.write((i >>> 24) & 0xff);
}
}
private void writeBE(int[] values, OutputStream os) throws IOException {
for (int i : values) {
os.write((i >>> 24) & 0xff);
os.write((i >> 16) & 0xff);
os.write((i >> 8) & 0xff);
os.write(i & 0xff);
}
}
private void writeLE16(int[] values, OutputStream os) throws IOException {
for (int i : values) {
os.write(i & 0xff);
os.write((i >> 8) & 0xff);
}
}
private void writeBE16(int[] values, OutputStream os) throws IOException {
for (int i : values) {
os.write((i >> 8) & 0xff);
os.write(i & 0xff);
}
}