public void doGetDAP2Data(ReqState rs) throws Exception { HttpServletResponse response = rs.getResponse(); GuardedDataset ds = null; try { ds = getDataset(rs); if (null == ds) return; response.setContentType("application/octet-stream"); response.setHeader("XDODS-Server", getServerVersion()); response.setHeader("Content-Description", "dods-data"); ServletOutputStream sOut = response.getOutputStream(); OutputStream bOut; DeflaterOutputStream dOut = null; if (rs.getAcceptsCompressed() && allowDeflate) { response.setHeader("Content-Encoding", "deflate"); dOut = new DeflaterOutputStream(sOut); bOut = new BufferedOutputStream(dOut); } else { bOut = new BufferedOutputStream(sOut); } ServerDDS myDDS = ds.getDDS(); CEEvaluator ce = new CEEvaluator(myDDS); ce.parseConstraint(rs); checkSize(myDDS, false); // Send the constrained DDS back to the client PrintWriter pw = new PrintWriter(new OutputStreamWriter(bOut)); myDDS.printConstrained(pw); // Send the Data delimiter back to the client pw.flush(); bOut.write("\nData:\n".getBytes()); bOut.flush(); // Send the binary data back to the client DataOutputStream sink = new DataOutputStream(bOut); ce.send(myDDS.getEncodedName(), sink, ds); sink.flush(); // Finish up sending the compressed stuff, but don't // close the stream (who knows what the Servlet may expect!) if (null != dOut) dOut.finish(); bOut.flush(); } finally { // release lock if needed if (ds != null) ds.release(); } }