KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > DataOutput


1 package dinamica;
2
3 import java.io.*;
4 import javax.servlet.ServletOutputStream JavaDoc;
5 import java.util.*;
6
7 /**
8  * DataOutput<br>
9  * 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     /**
24      * Serialize a HashMap containing Recordsets
25      * and transmit them over the servlet OutputStream
26      */

27     public void print(GenericTransaction data) throws Throwable JavaDoc
28     {
29         
30         //retrieve hashmap containing all published recordsets
31
HashMap obj = data.getData();
32         
33         //serialize obj to byte array
34
ByteArrayOutputStream bout = new ByteArrayOutputStream();
35         ObjectOutputStream out = new ObjectOutputStream(bout);
36         out.writeObject(obj);
37         out.close();
38         byte buffer[] = bout.toByteArray();
39         
40         //print buffer
41
getResponse().setContentType("application/octet-stream");
42         getResponse().setContentLength(buffer.length);
43         ServletOutputStream JavaDoc sout = getResponse().getOutputStream();
44         sout.write(buffer);
45         sout.close();
46         
47     }
48
49 }
50
Popular Tags