01: package dinamica;
02:
03: import java.io.*;
04: import javax.servlet.ServletOutputStream;
05: import java.util.*;
06:
07: /**
08: * DataOutput<br>
09: * Output module that serializes the internal HashMap
10: * object mantained by the Transaction object, which
11: * does contain all the published Recordsets. As a result,
12: * all Recordsets arre transmitted as byte stream over HTTP
13: * to the client who sent the request.
14: * <br><br>
15: * Creation date: 08/06/2004<br>
16: * (c) 2004 Martin Cordova y Asociados<br>
17: * http://www.martincordova.com<br>
18: * @author Martin Cordova dinamica@martincordova.com
19: */
20: public class DataOutput extends GenericOutput {
21:
22: /**
23: * Serialize a HashMap containing Recordsets
24: * and transmit them over the servlet OutputStream
25: */
26: public void print(GenericTransaction data) throws Throwable {
27:
28: //retrieve hashmap containing all published recordsets
29: HashMap<String, Recordset> obj = data.getData();
30:
31: //serialize obj to byte array
32: ByteArrayOutputStream bout = new ByteArrayOutputStream();
33: ObjectOutputStream out = new ObjectOutputStream(bout);
34: out.writeObject(obj);
35: out.close();
36: byte buffer[] = bout.toByteArray();
37:
38: //print buffer
39: getResponse().setContentType("application/octet-stream");
40: getResponse().setContentLength(buffer.length);
41: ServletOutputStream sout = getResponse().getOutputStream();
42: sout.write(buffer);
43: sout.close();
44:
45: }
46:
47: }
|