00001 package edu.stanford.hci.r3.pen.streaming.data;
00002
00003 import java.io.BufferedOutputStream;
00004 import java.io.IOException;
00005 import java.net.Socket;
00006
00007 import edu.stanford.hci.r3.PaperToolkit;
00008 import edu.stanford.hci.r3.pen.PenSample;
00009 import edu.stanford.hci.r3.util.SystemUtils;
00010
00022 public class PenServerJavaObjectXMLSender implements PenServerSender {
00023
00024 private BufferedOutputStream bos;
00025
00026 private Socket sock;
00027
00032 public PenServerJavaObjectXMLSender(Socket s) throws IOException {
00033 sock = s;
00034 bos = new BufferedOutputStream(s.getOutputStream());
00035 }
00036
00040 public void destroy() {
00041 try {
00042 if (bos != null) {
00043 bos.close();
00044 bos = null;
00045 }
00046 if (sock != null) {
00047 sock.close();
00048 sock = null;
00049 }
00050 } catch (IOException ioe) {
00051 System.out.println("Got exception when destroying JavaServerOutput: "
00052 + ioe.getLocalizedMessage());
00053 }
00054 }
00055
00064 public void sendSample(PenSample as) throws IOException {
00065 String xmlString = PaperToolkit.toXML(as);
00066
00067
00068 if (xmlString.contains("\n")) {
00069 xmlString = xmlString.replace("\n", "");
00070 }
00071
00072
00073 if (xmlString.contains(" ")) {
00074 xmlString = xmlString.replace(" ", "");
00075 }
00076
00077
00078 bos.write((xmlString + SystemUtils.LINE_SEPARATOR).getBytes());
00079 bos.flush();
00080 }
00081
00082 }