6 public class HTTPServices {
8 static private String webRoot = ".";
10 static private FileInputStream get_reader(String fileName,HTTPResponse resp) throws IOException {
11 // if(fileName.equals("/daytime")){
12 // String date_str = (new Date()).toString();
13 // resp.sentBytes = date_str.length();
15 // new StringReader(date_str);
18 if(fileName.equals("/viewlog"))
19 fileName = LogFile.log_file_name;
21 fileName = webRoot + fileName;
23 File f = new File(fileName);
24 resp.sentBytes = f.length();
25 return new FileInputStream(f);
28 public static void GET_handler(String fileName, OutputStream out, HTTPResponse resp) {
30 FileInputStream reader = null;
34 if((reader = HEAD_handler_int(fileName,out,resp)) == null) return;
36 buffer = new byte[1024];
39 while((size = reader.read(buffer,0,buffer.length)) != -1)
40 out.write(buffer,0,size);
42 } catch(IOException e) {
44 resp.returnCode = 501; // error during transmision
49 public static void POST_handler(String fileName, OutputStream out, HTTPResponse resp) {
50 GET_handler(fileName,out, resp);
53 static private FileInputStream HEAD_handler_int(String fileName,
54 OutputStream out,HTTPResponse resp) {
55 FileInputStream reader = null;
58 reader = get_reader(fileName, resp);
59 resp.returnCode = 200;
60 } catch(IOException e) {
61 resp.returnCode = 404; // file not found
64 if(resp.returnCode == 200)
65 HTTPHeader.send_header(out, resp.returnCode, fileName, resp.sentBytes);
67 HTTPHeader.send_header(out, resp.returnCode, fileName, 0);
75 public static void HEAD_handler(String fileName,
76 OutputStream out, HTTPResponse resp) {
77 HEAD_handler_int(fileName,out,resp);