graphImageCache.put(request.getQueryString(), filename); ServletUtilities.sendTempFile(filename, response);
File oldFile = new File(System.getProperty("java.io.tmpdir"), filename); File cacheFile = new File(System.getProperty("java.io.tmpdir"), filename + "_flymine"); FileChannel in = null; FileChannel out = null; try { in = new FileInputStream(oldFile).getChannel(); out = new FileOutputStream(cacheFile).getChannel(); in.transferTo (0, in.size(), out); } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } }  graphImageCache.put(request.getQueryString(), cacheFile.getName()); ServletUtilities.sendTempFile(cacheFile.getName(), response);
    public ActionForward microarray(            ActionMapping mapping,            ActionForm form,            HttpServletRequest request,            HttpServletResponse response) throws Exception {        HttpSession session = request.getSession();        Map graphImageCache = (Map) session.getServletContext()            .getAttribute(Constants.GRAPH_CACHE);        ObjectStore os = (ObjectStore) session.getServletContext()            .getAttribute(Constants.OBJECTSTORE);        String experiment = request.getParameter("experiment");        String gene = request.getParameter("gene");        Results results = MicroArrayHelper.queryMicroArrayResults(experiment, gene, os);        Iterator iter = results.iterator();        DefaultCategoryDataset xyDataset = new DefaultCategoryDataset();        while (iter.hasNext()) {            ResultsRow rr = (ResultsRow) iter.next();            MicroArrayResult result = (MicroArrayResult) rr.get(0);            // TODO hack for Arbeitman experiment, should set display label in assay to simplify            String label = ((MicroArrayAssay) rr.get(1)).getSample2();            if (label != null && !(label.equals(""))) {                String series = label.substring(label.indexOf(':'), label.indexOf('-')).trim();                // TODO Calculate Log2, should be a flag to set scale                xyDataset.addValue((Math.log(result.getValue().floatValue()) / logE2),                                   series, (Integer) rr.get(2));            }        }        CategoryAxis xAxis = new CategoryAxis(null);        NumberAxis yAxis = new NumberAxis("Log2 Ratio");        LineAndShapeRenderer renderer = new LineAndShapeRenderer();        configureXaxis(xAxis, request);        configureYaxis(yAxis, request);        configureRenderer(renderer, request);        CategoryPlot plot = new CategoryPlot(xyDataset, xAxis, yAxis, renderer);        JFreeChart chart = new JFreeChart(null,                AbstractRenderer.DEFAULT_VALUE_LABEL_FONT, plot, true);        configureChart(chart, request);        int width = Integer.parseInt(request.getParameter("width"));        int height = Integer.parseInt(request.getParameter("height"));        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());        String filename = ServletUtilities.saveChartAsPNG(chart, width, height, info, session);        graphImageCache.put(request.getQueryString(), filename);        ServletUtilities.sendTempFile(filename, response);        return null;    }