I am trying to debug a 3d file format exporter which sometimes exports files that aren't working everywhere(some programs open them some don't). While I was reading the documentation there seems to be a line that I cannot wrap my head around:
6.4 Objects
The objects in each section are serialized as an array of bytes, one after the other. This array of bytes will either be compressed (if CompressionScheme is 1) or it will be uncompressed. If it is compressed, it is compressed as a single chunk of data, not as separate objects. Zero bits must be padded in the end to make the Objects field byte aligned.
The documentation can be found at http://www.j2megame.org/j2meapi/JSR_184_Mobile_3D_Graphics_API_1_1/file-format.html
And this is the current code I am using:
protected void write(M3GOutputStream os,ArrayList table) throws IOException
{
ByteArrayOutputStream baos=new ByteArrayOutputStream();
writeObjects(new M3GOutputStream(baos),table);
uncompressedLength=baos.size();
byte data[]=baos.toByteArray();
if(!M3GToolkit.useZlibCompression)
compressionScheme = UNCOMPRESSED;
if (compressionScheme==ZLIB)
{
Deflater deflater=new Deflater(Deflater.BEST_COMPRESSION,false);
deflater.setInput(data);
deflater.finish();
byte compressed[]=new byte[data.length<<1];
int length=deflater.deflate(compressed);
data=new byte[length];
System.arraycopy(compressed,0,data,0,length);
deflater.end();
}
os.resetAdler32();
os.writeByte(compressionScheme);
os.writeUInt32(totalSectionLength=data.length+13);
os.writeUInt32(uncompressedLength);
os.write(data);
os.writeUInt32(checksum=(int)os.getAdler32Value());
}