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();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.