01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver.servlets;
06:
07: import org.geoserver.ows.DispatcherOutputStream;
08: import org.geoserver.ows.ServiceStrategy;
09: import java.io.BufferedOutputStream;
10: import java.io.IOException;
11: import java.io.OutputStream;
12: import javax.servlet.http.HttpServletResponse;
13:
14: /** Fast and Dangeroud service strategy.
15: *
16: * <p>
17: * Will fail when a ServiceException is encountered on writeTo, and will not
18: * tell the user about it!
19: * </p>
20: *
21: * <p>
22: * This is the worst case scenario, you are trading speed for danger by using
23: * this ServiceStrategy.
24: * </p>
25: *
26: * @author jgarnett
27: */
28: public class SpeedStrategy implements ServiceStrategy {
29: public String getId() {
30: return "SPEED";
31: }
32:
33: /** DOCUMENT ME! */
34: private OutputStream out = null;
35:
36: /**
37: * Works against the real output stream provided by the response.
38: *
39: * <p>
40: * This is dangerous of course, but fast and exciting.
41: * </p>
42: *
43: * @param response Response provided by doService
44: *
45: * @return An OutputStream that works against, the response output stream.
46: *
47: * @throws IOException If response output stream could not be aquired
48: */
49: public DispatcherOutputStream getDestination(
50: HttpServletResponse response) throws IOException {
51: out = response.getOutputStream();
52: out = new BufferedOutputStream(out);
53:
54: return new DispatcherOutputStream(out);
55: }
56:
57: /**
58: * Completes writing to Response.getOutputStream.
59: *
60: * @throws IOException If Response.getOutputStream not available.
61: */
62: public void flush(HttpServletResponse response) throws IOException {
63: if (out != null) {
64: out.flush();
65: }
66: }
67:
68: /* (non-Javadoc)
69: * @see org.vfny.geoserver.servlets.AbstractService.ServiceStrategy#abort()
70: */
71: public void abort() {
72: // out.close();
73: }
74:
75: public Object clone() throws CloneNotSupportedException {
76: return new SpeedStrategy();
77: }
78: }
|