Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../img/srcFileCovDistChart7.png 74% of files have more coverage
19   87   7   3.8
2   44   0.37   5
5     1.4  
1    
 
  WebServer       Line # 13 19 7 65.4% 0.65384614
 
  (1)
 
1    package org.qedeq.base.test;
2   
3    /**
4    * This web server code was adapted from sun's simple web server tutorial:
5    * http://java.sun.com/developer/technicalArticles/Networking/Webserver/
6    *
7    */
8   
9    import java.io.File;
10    import java.io.IOException;
11    import java.net.ServerSocket;
12   
 
13    public class WebServer {
14   
15    /** The web server's virtual root. */
16    private final File root;
17   
18    /** Timeout on client connections. */
19    private final int timeout;
20   
21    /** We work on this port. */
22    private final int port;
23   
24    /** Debug output? */
25    private boolean debug = true;
26   
27    /** Thread the server works in. */
28    private Thread thread;
29   
30    private ServerSocket ss;
31   
 
32  0 toggle public static void main(String[] a) throws Exception {
33  0 final WebServer server = new WebServer();
34  0 server.start();
35    // IoUtility.sleep(50000);
36    // server.stop();
37    }
38   
39    /**
40    * Default constructor.
41    *
42    * @throws Exception
43    */
 
44  0 toggle public WebServer() {
45  0 this.port = 3081;
46  0 this.root = new File(".");
47  0 this.debug = true;
48  0 this.timeout = 5000;
49    }
50   
51    /**
52    * Construct a web server.
53    *
54    * @param port Port we should listen.
55    * @param root Root point of served file system.
56    * @param timeout Client timeout.
57    * @param debug Output debug messages?
58    */
 
59  1 toggle public WebServer(final int port, final File root, final int timeout, final boolean debug) {
60  1 this.port = port;
61  1 this.root = root;
62  1 this.timeout = timeout;
63  1 this.debug = debug;
64    }
65   
 
66  1 toggle public synchronized void start() throws IOException {
67  1 ss = new ServerSocket(port);
68  1 WebServerWorker ws = new WebServerWorker(timeout, root, ss, debug);
69  1 thread = (new Thread(ws, "additional worker"));
70    // thread.setDaemon(true);
71  1 thread.start();
72    }
73   
 
74  1 toggle public synchronized void stop() {
75  1 thread.interrupt();
76  1 thread = null;
77  1 if (ss != null) {
78  1 try {
79  1 ss.close();
80    } catch (Exception e) {
81    // ignore
82    }
83    }
84    }
85   
86    }
87