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.pen.PenSample;
00008 import edu.stanford.hci.r3.util.SystemUtils;
00009
00021 public class PenServerPlainTextSender implements PenServerSender {
00022
00023 private Socket socket;
00024
00025 private BufferedOutputStream bos;
00026
00031 public PenServerPlainTextSender(Socket sock) throws IOException {
00032 socket = sock;
00033 bos = new BufferedOutputStream(sock.getOutputStream());
00034 }
00035
00039 public void sendSample(PenSample as) throws IOException {
00040 bos.write((as.toCommaSeparatedString() + SystemUtils.LINE_SEPARATOR).getBytes());
00041 bos.flush();
00042 }
00043
00047 public void destroy() {
00048 try {
00049 if (bos != null) {
00050 bos.close();
00051 bos = null;
00052 }
00053 if (socket != null) {
00054 socket.close();
00055 socket = null;
00056 }
00057 } catch (IOException ioe) {
00058 System.out.println("Got exception when destroying PlainTextServerOutput: "
00059 + ioe.getLocalizedMessage());
00060 }
00061 }
00062 }