How to keep the stream of ImageOutputStream in memory?
<p>The following code uses twelvemonkeys to create a tiff file. The created file gets flushed to disk automatically. But I would like the file to be created in memory only. How to achive this with the ImageOutputStream?</p>

<pre><code>try {
  // Create output stream
  ImageOutputStream output = ImageIO.createImageOutputStream(targetFile);

  try {
    writer.setOutput(output);

    ImageWriteParam param = writer.getDefaultWriteParam();
    TIFFImageWriteParam tiffWriteParam = (TIFFImageWriteParam) param;
    tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);     

    TIFFImageMetadata metadata = (TIFFImageMetadata) createMetadata(sourceFile);     

    // Set dpi
    String nativeFormat = TIFFMedataFormat.SUN_NATIVE_IMAGE_METADATA_FORMAT_NAME;
    // Node nativeTree = metadata.getAsTree(nativeFormat);
    IIOMetadataNode newTree =
        new IIOMetadataNode("com_sun_media_imageio_plugins_tiff_image_1.0");
    IIOMetadataNode ifdNode = new IIOMetadataNode("TIFFIFD");
    newTree.appendChild(ifdNode);
    createTIFFFieldNode(ifdNode, TIFF.TAG_RESOLUTION_UNIT, TIFF.TYPE_SHORT, 2);
    createTIFFFieldNode(ifdNode, TIFF.TAG_X_RESOLUTION, TIFF.TYPE_RATIONAL, new Rational(300));
    createTIFFFieldNode(ifdNode, TIFF.TAG_Y_RESOLUTION, TIFF.TYPE_RATIONAL, new Rational(300));
    metadata.mergeTree(nativeFormat, newTree);

    IIOImage iioimage = new IIOImage(image, null, metadata);
    writer.write(metadata, iioimage, tiffWriteParam);
  } finally {      
    output.close();
  }
} finally {  
  writer.dispose();
}
</code></pre>