/// <summary> This method reads the codestream and writes the file format wrapper and
/// the codestream to the same file
///
/// </summary>
/// <returns> The number of bytes increases because of the file format
///
/// </returns>
/// <exception cref="java.io.IOException">If an I/O error ocurred.
///
/// </exception>
public virtual int writeFileFormat()
{
byte[] codestream;
try
{
// Read and buffer the codestream
fi = new BEBufferedRandomAccessFile(filename, "rw+");
codestream = new byte[clength];
fi.readFully(codestream, 0, clength);
// Write the JP2_SINATURE_BOX
fi.seek(0);
fi.writeInt(0x0000000c);
fi.writeInt(CSJ2K.j2k.fileformat.FileFormatBoxes.JP2_SIGNATURE_BOX);
fi.writeInt(0x0d0a870a);
// Write File Type box
writeFileTypeBox();
// Write JP2 Header box
writeJP2HeaderBox();
// Write the Codestream box
writeContiguousCodeStreamBox(codestream);
fi.close();
}
catch (System.Exception e)
{
throw new System.ApplicationException("Error while writing JP2 file format(2): " + e.Message + "\n" + e.StackTrace);
}
if (bpcVaries)
return 12 + FTB_LENGTH + 8 + IHB_LENGTH + CSB_LENGTH + BPC_LENGTH + nc + 8;
else
return 12 + FTB_LENGTH + 8 + IHB_LENGTH + CSB_LENGTH + 8;
}