55import java .util .*;
66import java .util .zip .*;
77
8- //import javax.swing.SwingUtilities;
98
109/**
1110 * This code is placed here in anticipation of running the reference from an
1211 * internal web server that reads the docs from a zip file, instead of using
1312 * thousands of .html files on the disk, which is really inefficient.
1413 * <p/>
15- * This is a very simple, multi-threaded HTTP server, originally based on
14+ * This is a very simple, multi-threaded HTTP server, originally based on
1615 * <a href="http://j.mp/6BQwpI">this</a> article on java.sun.com.
1716 */
1817public class WebServer implements HttpConstants {
1918
2019 /* Where worker threads stand idle */
2120 static Vector threads = new Vector ();
22-
21+
2322 /* the web server's virtual root */
2423 //static File root;
2524
@@ -29,7 +28,7 @@ public class WebServer implements HttpConstants {
2928 /* max # worker threads */
3029 static int workers = 5 ;
3130
32- // static PrintStream log = System.out;
31+ // static PrintStream log = System.out;
3332
3433
3534 /*
@@ -88,7 +87,7 @@ static void printProps() {
8887 }
8988 */
9089
91-
90+
9291 /* print to stdout */
9392// protected static void p(String s) {
9493// System.out.println(s);
@@ -105,7 +104,7 @@ protected static void log(String s) {
105104// }
106105 }
107106
108-
107+
109108 //public static void main(String[] a) throws Exception {
110109 static public int launch (String zipPath ) throws IOException {
111110 final ZipFile zip = new ZipFile (zipPath );
@@ -226,7 +225,7 @@ public synchronized void run() {
226225 }
227226 }
228227
229-
228+
230229 void handleClient () throws IOException {
231230 InputStream is = new BufferedInputStream (s .getInputStream ());
232231 PrintStream ps = new PrintStream (s .getOutputStream ());
@@ -240,7 +239,7 @@ void handleClient() throws IOException {
240239 buf [i ] = 0 ;
241240 }
242241 try {
243- // We only support HTTP GET/HEAD, and don't support any fancy HTTP
242+ // We only support HTTP GET/HEAD, and don't support any fancy HTTP
244243 // options, so we're only interested really in the first line.
245244 int nread = 0 , r = 0 ;
246245
@@ -254,7 +253,7 @@ void handleClient() throws IOException {
254253 nread += r ;
255254 for (; i < nread ; i ++) {
256255 if (buf [i ] == (byte )'\n' || buf [i ] == (byte )'\r' ) {
257- break outerloop ; // read one line
256+ break outerloop ; // read one line
258257 }
259258 }
260259 }
@@ -312,7 +311,7 @@ void handleClient() throws IOException {
312311 send404 (ps );
313312 }
314313 /*
315- String fname =
314+ String fname =
316315 (new String(buf, 0, index, i-index)).replace('/', File.separatorChar);
317316 if (fname.startsWith(File.separator)) {
318317 fname = fname.substring(1);
@@ -338,7 +337,7 @@ void handleClient() throws IOException {
338337 }
339338 }
340339
341-
340+
342341 boolean printHeaders (ZipEntry targ , PrintStream ps ) throws IOException {
343342 boolean ret = false ;
344343 int rCode = 0 ;
@@ -386,8 +385,8 @@ boolean printHeaders(ZipEntry targ, PrintStream ps) throws IOException {
386385 ps .write (EOL ); // adding another newline here [fry]
387386 return ret ;
388387 }
389-
390-
388+
389+
391390 boolean printHeaders (File targ , PrintStream ps ) throws IOException {
392391 boolean ret = false ;
393392 int rCode = 0 ;
@@ -432,7 +431,7 @@ boolean printHeaders(File targ, PrintStream ps) throws IOException {
432431 return ret ;
433432 }
434433
435-
434+
436435 void send404 (PrintStream ps ) throws IOException {
437436 ps .write (EOL );
438437 ps .write (EOL );
@@ -442,7 +441,7 @@ void send404(PrintStream ps) throws IOException {
442441 ps .write (EOL );
443442 }
444443
445-
444+
446445 void sendFile (File targ , PrintStream ps ) throws IOException {
447446 InputStream is = null ;
448447 ps .write (EOL );
@@ -454,8 +453,8 @@ void sendFile(File targ, PrintStream ps) throws IOException {
454453 }
455454 sendFile (is , ps );
456455 }
457-
458-
456+
457+
459458 void sendFile (InputStream is , PrintStream ps ) throws IOException {
460459 try {
461460 int n ;
@@ -489,19 +488,19 @@ static void fillMap() {
489488 setSuffix (".snd" , "audio/basic" );
490489 setSuffix (".au" , "audio/basic" );
491490 setSuffix (".wav" , "audio/x-wav" );
492-
491+
493492 setSuffix (".gif" , "image/gif" );
494493 setSuffix (".jpg" , "image/jpeg" );
495494 setSuffix (".jpeg" , "image/jpeg" );
496-
495+
497496 setSuffix (".htm" , "text/html" );
498497 setSuffix (".html" , "text/html" );
499- setSuffix (".css" , "text/css" );
498+ setSuffix (".css" , "text/css" );
500499 setSuffix (".java" , "text/javascript" );
501-
500+
502501 setSuffix (".txt" , "text/plain" );
503502 setSuffix (".java" , "text/plain" );
504-
503+
505504 setSuffix (".c" , "text/plain" );
506505 setSuffix (".cc" , "text/plain" );
507506 setSuffix (".c++" , "text/plain" );
0 commit comments