01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04:
05: /**
06: * The file stream
07: *
08: * @author Victor Zhigunov
09: * @version 0.4.0
10: */
11: public class FileStream extends PathStream {
12: public FileStream() {
13: }
14:
15: private File dir;
16:
17: /**
18: * @param session
19: * parent session
20: * @param outputstream
21: * linked output stream
22: * @param dir
23: * directory
24: */
25: public FileStream(Session session, OutputStream outputstream,
26: File dir) {
27: super (session, outputstream);
28: this .dir = dir;
29: }
30:
31: static private long count = System.currentTimeMillis();
32:
33: /**
34: * The local file
35: */
36: public File localFile;
37:
38: public void head(String method, String file, String version)
39: throws IOException {
40: super .head(method, file, version);
41: int i = path[1].indexOf('@');
42: if (i != -1)
43: path[1] = path[1].substring(i + 1);
44: path[1] = path[1].replace(':', '#');
45: String s = "";
46: for (i = 1; i < path.length - 1; i++)
47: s += path[i] + File.separatorChar;
48: s += path[i];
49: boolean b = false;
50: for (char c : ":;?\"*><|".toCharArray())
51: if (s.indexOf(c) != -1) {
52: b = true;
53: break;
54: }
55: if (b || (dir.getAbsolutePath() + s).length() > 254)
56: s = path[1] + File.separatorChar + String.valueOf(count++);
57: else
58: s = s.replace("%20", " ");
59: localFile = new File(dir, s);
60: }
61: }
|