* @param out the stream to write to
*/
public void writeOut(byte headerA, byte headerB, long type, Record[] children, OutputStream out) throws IOException {
// If we have a mutable output stream, take advantage of that
if(out instanceof MutableByteArrayOutputStream) {
MutableByteArrayOutputStream mout =
(MutableByteArrayOutputStream)out;
// Grab current size
int oldSize = mout.getBytesWritten();
// Write out our header, less the size
mout.write(new byte[] {headerA,headerB});
byte[] typeB = new byte[2];
LittleEndian.putShort(typeB,(short)type);
mout.write(typeB);
mout.write(new byte[4]);
// Write out the children
for(int i=0; i<children.length; i++) {
children[i].writeOut(mout);
}
// Update our header with the size
// Don't forget to knock 8 more off, since we don't include the
// header in the size
int length = mout.getBytesWritten() - oldSize - 8;
byte[] size = new byte[4];
LittleEndian.putInt(size,0,length);
mout.overwrite(size, oldSize+4);
} else {
// Going to have to do it a slower way, because we have
// to update the length come the end
// Create a ByteArrayOutputStream to hold everything in