1 /*
2 * Trip Tracker, a real-time position tracking system for the Internet.
3 * Copyright (C) 2006 Team Trip Tracker
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 package triptracker.testing.compress;
21
22 import java.io.BufferedReader;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.InputStreamReader;
26 import java.net.Socket;
27
28 public class ServerWorker extends Thread {
29 Socket s = null;
30
31 public ServerWorker(Socket s) {
32 this.s = s;
33 start();
34 }
35
36 @Override
37 public void run() {
38 try {
39 InputStream in = s.getInputStream();
40 // InputStream in = (InputStream) (new DebugProxy(s.getInputStream()));
41 CompressedBlockInputStream inCompress =
42 new CompressedBlockInputStream(in);
43
44 // Build a Reader object that wraps the
45 // (decompressed) socket input stream.
46 BufferedReader inBuff = new BufferedReader(
47 new InputStreamReader(inCompress));
48 // String line = inBuff.readLine();
49 // while (line != null) {
50 // System.out.println(line);
51 // line = inBuff.readLine();
52 // }
53
54 int byteCount = 0;
55
56 byte[] buf = new byte[1024];
57 // int bytes = inCompress.read(buf);
58 int bytes = in.read(buf);
59 System.out.println("Starting receiving...");
60 long time = System.currentTimeMillis ();
61 while (bytes > 0) {
62 byteCount += bytes;
63 System.currentTimeMillis();
64 // bytes = inCompress.read(buf);
65 bytes = in.read(buf);
66 }
67 System.out.println("Received uncompressed " + byteCount + " bytes");
68 System.out.println("Runtime: "
69 + ((double) (System.currentTimeMillis() - time) / 1000)
70 + " sec.");
71 System.out.flush();
72 } catch (IOException ioe) {
73 ioe.printStackTrace();
74 }
75 }
76 }