Added a responder to serve static content from the classloader.
[jsvc.git] / src / dolda / jsvc / util / Misc.java
CommitLineData
78f5d120
FT
1package dolda.jsvc.util;
2
7779099a 3import dolda.jsvc.*;
78f5d120 4import java.util.*;
7779099a 5import java.io.*;
78f5d120
FT
6
7public class Misc {
8 private static Map<Integer, String> stext = new HashMap<Integer, String>();
9
10 static {
11 stext.put(200, "OK");
c25c3aad
FT
12 stext.put(300, "Multiple Choices");
13 stext.put(301, "Permanently Moved");
14 stext.put(302, "Temporarily Moved");
15 stext.put(303, "See Other");
7779099a 16 stext.put(304, "Not Modified");
c25c3aad
FT
17 stext.put(400, "Bad Request");
18 stext.put(401, "Authentication Required");
19 stext.put(403, "Access Forbidden");
20 stext.put(404, "Resource Not Found");
21 stext.put(500, "Server Error");
78f5d120
FT
22 }
23
24 public static String statustext(int status) {
25 String text;
26 if((text = stext.get(status)) != null)
27 return(text);
c25c3aad
FT
28 return("Server Flimsiness");
29 }
30
31 public static String stripslashes(String p, boolean beg, boolean end) {
32 while(end && (p.length() > 0) && (p.charAt(p.length() - 1) == '/'))
33 p = p.substring(0, p.length() - 1);
34 while(beg && (p.length() > 0) && (p.charAt(0) == '/'))
35 p = p.substring(1);
36 return(p);
78f5d120 37 }
7779099a
FT
38
39 public static void cpstream(InputStream in, OutputStream out) throws IOException {
40 byte[] buf = new byte[4096];
41 while(true) {
42 int ret = in.read(buf, 0, buf.length);
43 if(ret < 0)
44 return;
45 out.write(buf, 0, ret);
46 }
47 }
48
49 public static Responder stdroot(Responder root) {
50 Responder ret = root;
51 ret = new Rehandler(ret);
52 ret = new ErrorHandler(ret);
53 return(ret);
54 }
78f5d120 55}