01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04: import java.util.*;
05: import vicazh.hyperpool.stream.*;
06: import vicazh.hyperpool.Start;
07:
08: class CacheServerStream extends ServerStream {
09: CacheServerStream(Session session, OutputStream outputstream) {
10: super (session, outputstream);
11: }
12:
13: private OutputStream stream;
14:
15: public void head(String version, int code, String message)
16: throws IOException {
17: if ((code == NOT_MODIFIED || code == PARTIAL_CONTENT)
18: && ((CacheSession) session).session != null) {
19: stream = outputstream;
20: outputstream = new NullStream(outputstream);
21: }
22: super .head(version, code, message);
23: }
24:
25: private long lInt;
26:
27: public void header() throws IOException {
28: if (stream == null)
29: super .header();
30: else {
31: outputstream = stream;
32: stream = null;
33: super .head(getVersion(), OK, "");
34: for (Map.Entry<String, String> e : ((CacheSession) session).session
35: .getServer().getFields().entrySet())
36: field(e.getKey(), e.getValue());
37: super .header();
38: InputStream s = new BufferedInputStream(
39: new FileInputStream(((CacheClientStream) session
40: .getClient()).localFile));
41: int i;
42: while ((i = s.read()) != -1) {
43: super .content(i);
44: lInt++;
45: }
46: s.close();
47: Start.logger.fine("file:" + session.getClient().getFile());
48: }
49: }
50:
51: private long lExt;
52:
53: public void content(int b) throws IOException {
54: super .content(b);
55: lExt++;
56: }
57:
58: public void end() {
59: super .end();
60: ((CacheService) connection.element).add(lExt, lInt);
61: }
62: }
|