Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the processRequest() method in the SimpleWebServer.java file to use this

ID: 3591174 • Letter: M

Question

Modify the processRequest() method in the SimpleWebServer.java file to use this file storage and logging code:

public void storeFile (BufferedReader br, OutputStreamWriter osw,

                       String pathname) throws Exception {

FileWriter fw = null;

try {

    fw = new FileWriter(pathname);

    String s = br.readLine();

    while (s != null) {

      fw.write(s);

      s = br.readLine();

    }

    fw.close();

    osw.write("HTTP/1.0 201 Created");

} catch(Exception e) {

    osw.write("HTTP/1.0 500 Internal Server Error");

}

}

public void logEntry(String filename,String record) {

FileWriter fw = new FileWriter (filename, true);

fw.write(getTimestamp()+ " " + record);

fw.close();

}

public String getTimestamp() {

return (new Date()).toString();

}

***********************************************************************

SimpleWebServer.java code:

Explanation / Answer

SimpleWebServer.java code:

The following code is the modified version of file storage and logging functionality in simplewebserver.java file.

public void storeFile (BufferedReader br, OutputStreamWriter osw,

                       String pathname) throws Exception {

FileWriter fw = null;

try {

    fw = new FileWriter(pathname);

    String s = br.readLine();

    while (s != null) {

      fw.write(s);

      s = br.readLine();

    }

    fw.close();

    osw.write("HTTP/1.0 201 Created");

} catch(Exception e) {

    osw.write("HTTP/1.0 500 Internal Server Error");

}

}

public void logEntry(String filename,String record) {

FileWriter fw = new FileWriter (filename, true);

fw.write(getTimestamp()+ " " + record);

fw.close();

}

public String getTimestamp() {

return (new Date()).toString();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote