* Stores the specified image in a Storage object.
*/
private static Storage storeImage(StorageProvider storageProvider,
BufferedImage image, String formatName) throws IOException {
// An output stream that is capable of building a Storage object.
StorageOutputStream out = storageProvider.createStorageOutputStream();
// Write the image to our output stream. A StorageOutputStream can be
// used to create attachments using any API that supports writing a
// document to an output stream, e.g. iText's PdfWriter.
ImageIO.write(image, formatName, out);
// Implicitly closes the output stream and returns the data that has
// been written to it.
return out.toStorage();
}