Question
Does anyone know what the error in my code may be? I'll bolden the line that the error occurs on. The error can be found
Does anyone know what the error in my code may be? I'll bolden the line that the error occurs on. The error can be found in WebWorker.java file. Note that this is the code I have for developing a WebServer that pertains to software development in the Java programming language.
/** * Read the HTTP request header. **/
WebWorker.java method:
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.Socket; import java.text.DateFormat; import java.util.Date; import java.util.TimeZone; import java.lang.*; import java.io.*; import java.net.*; import java.util.*; import java.text.*;
private void readHTTPRequest(InputStream is) { String line; BufferedReader r = new BufferedReader(new InputStreamReader(is)); int check = 1; while (true) { try { while (!r.ready()) Thread.sleep(1); line = r.readLine(); if (check > 0) { StringTokenizer tokens = new StringTokenizer(line); tokens.nextToken(); fileName = tokens.nextToken(); //Prepend a "." so that a file request is within directory being worked with by user fileName = "." + fileName; if (fileName.endsWith(".ico")) { fileType = "image/x-icon"; } //end if if (fileName.endsWith(".png")) { fileType = "image/png"; } //end if else { MimetypesfileTypeMap mimeMap = new MimetypesfileTypeMap(); fileType = mimeMap.getContentType(fileName); } //end else type = fileType.split("/")[0]; System.out.println("********"); System.out.println(fileType); System.out.println("********"); fis = null; fileExists = true; try { fis = new FileInputStream(fileName); } //end try catch (FileNotFoundException e) { fileExists = false; } //end catch check --; } //end outer if block //This line keeps showing the line of code that the processor displays to the user System.err.println("Request line: (" + line + ")"); if (line.length() == 0) break; } //end outer try block catch (Exception e) { System.err.println("Request error :" + e); break; } //end catch } //end while (true) loop return; } //end readHTTPRequest method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started