protected OutputStream streamTopiaryGraphics(File file, String filetypeName, Graphics2DStreamThunk thunk) {
        Writer writerOut = null;
        OutputStream streamOut = null;
    	try {
    		// If we are not layed out we need to be
    		if (!layedOut) {
    			layout();
    		}
    		
            // Paint onto the generator
            this.paint(thunk.getGraphics2D());

            // Stream out 
            if (file != null) {
            	// File is provided
            	streamOut = new FileOutputStream(file);
            } else {
            	// No file, use ByteArrayOutputStream
            	streamOut = new ByteArrayOutputStream();
            }
	        writerOut = new OutputStreamWriter(streamOut, "UTF-8");
	        thunk.StreamOut(writerOut);
		} catch (Exception e) {
			String msg = String.format("Could not save as %s\nException of type %s\nwith the message\n\"%s\"", filetypeName, e.getClass().toString(), e.getMessage()); 
			System.out.print(msg);
			System.out.print("\n");
			e.printStackTrace();
			Alert.alert(MessageType.INFO, msg, null);
		} finally {
			try {
				if (writerOut != null) writerOut.close();
				if (streamOut != null) streamOut.close();
			} catch (Exception e) {
				// Do nothing
			} finally {
				writerOut = null;
			}
		}
    	
    	return streamOut;
	}