01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04: import java.util.*;
05: import java.util.logging.*;
06: import vicazh.hyperpool.Element;
07: import vicazh.hyperpool.*;
08: import vicazh.hyperpool.Start;
09: import vicazh.hyperpool.stream.*;
10: import vicazh.hyperpool.stream.Selector;
11:
12: class AgentsClientStream extends ClientStream {
13:
14: AgentsClientStream(Session session, OutputStream outputstream) {
15: super (session, outputstream == null ? new NullStream(
16: outputstream) : outputstream);
17: }
18:
19: private String agent;
20:
21: public void field(String s1, String s2) throws IOException {
22: if (s1.equalsIgnoreCase("User-Agent"))
23: agent = s2;
24: super .field(s1, s2);
25: }
26:
27: public void header() throws IOException {
28: if (outputstream instanceof NullStream) {
29: int index = ((SelectorMBean) connection.element).getDef();
30: if (agent != null) {
31: ((Element) connection.element).sendAttribute(
32: ControlListSelectorMBean.SEEK, agent);
33: index = ((ListSelectorMBean) connection.element)
34: .getIndex(agent);
35: }
36: outputstream = ((Selector) connection.element).get(
37: connection.getServer(), index);
38: ((AgentsConnection) connection).priority = (Priority) ((AgentsSelector) connection.element)
39: .getList().get(index);
40: head(getMethod(), getFile(), getVersion());
41: for (Map.Entry<String, String> e : getFields().entrySet())
42: super .field(e.getKey(), e.getValue());
43: }
44: super .header();
45: }
46:
47: public void content(int b) throws IOException {
48: try {
49: if (((AgentsConnection) connection).isReverse)
50: ((Priorities) ((ListSelectorMBean) connection.element)
51: .getList())
52: .serverwrite(((AgentsConnection) connection).priority);
53: else
54: ((Priorities) ((ListSelectorMBean) connection.element)
55: .getList())
56: .clientwrite(((AgentsConnection) connection).priority);
57: } catch (Exception e) {
58: Start.logger.log(Level.SEVERE, e.getMessage(), e);
59: }
60: super.content(b);
61: }
62: }
|