01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04:
05: class CacheClientStream extends FileStream {
06: CacheClientStream(Session session, OutputStream outputstream) {
07: super (session, outputstream, new File(
08: ((CacheService) session.connection.element).dir2path(),
09: ((CacheService) session.connection.element).cache));
10: }
11:
12: public void header() throws IOException {
13: check();
14: super .header();
15: }
16:
17: private static final String name = "If-Modified-Since";
18:
19: private String m;
20:
21: private boolean b;
22:
23: private void check() throws IOException {
24: if (b) {
25: if (m != null)
26: super .field("If-Modified-Since", m);
27: return;
28: }
29: if (!localFile.exists())
30: return;
31: File fileBase = ((CacheService) session.connection.element)
32: .getBase(localFile);
33: if (!fileBase.exists())
34: return;
35: if (fileBase.isDirectory())
36: return;
37: try {
38: Session sessionbase = (Session) ((CacheService) connection.element).reader
39: .getObject(fileBase);
40: if (!sessionbase.getClient().getFile().equals(getFile()))
41: return;
42: String s = (String) sessionbase.getServer().getFields()
43: .get("last-modified");
44: if (s == null)
45: return;
46: if (m != null && m.equals(s)) {
47: super .field("If-Modified-Since", m);
48: return;
49: }
50: String s2 = (String) sessionbase.getServer().getFields()
51: .get("content-length");
52: if (s2 == null)
53: return;
54: if (localFile.length() < Long.parseLong(s2)) {
55: s2 = (String) sessionbase.getServer().getFields().get(
56: "accept-ranges");
57: if (s2 == null)
58: return;
59: if (!s2.equalsIgnoreCase("bytes"))
60: return;
61: field("Range", "bytes=" + localFile.length() + "-");
62: } else
63: super .field(name, s);
64: ((CacheSession) session).session = sessionbase;
65: } catch (Exception e) {
66: }
67: }
68:
69: public void field(String s1, String s2) throws IOException {
70: if (s1.equalsIgnoreCase("Pragma")
71: && s2.equalsIgnoreCase("no-cache")
72: || s1.equalsIgnoreCase("Range"))
73: b = true;
74: if (s1.equalsIgnoreCase("If-Modified-Since"))
75: m = s2;
76: else
77: super.field(s1, s2);
78: }
79:
80: }
|