1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.spdy;
17
18 import io.netty.util.internal.StringUtil;
19
20
21
22
23 public class DefaultSpdySynStreamFrame extends DefaultSpdyHeadersFrame
24 implements SpdySynStreamFrame {
25
26 private int associatedStreamId;
27 private byte priority;
28 private boolean unidirectional;
29
30
31
32
33
34
35
36
37 public DefaultSpdySynStreamFrame(int streamId, int associatedStreamId, byte priority) {
38 super(streamId);
39 setAssociatedStreamId(associatedStreamId);
40 setPriority(priority);
41 }
42
43 @Override
44 public SpdySynStreamFrame setStreamId(int streamId) {
45 super.setStreamId(streamId);
46 return this;
47 }
48
49 @Override
50 public SpdySynStreamFrame setLast(boolean last) {
51 super.setLast(last);
52 return this;
53 }
54
55 @Override
56 public SpdySynStreamFrame setInvalid() {
57 super.setInvalid();
58 return this;
59 }
60
61 @Override
62 public int associatedStreamId() {
63 return associatedStreamId;
64 }
65
66 @Override
67 public SpdySynStreamFrame setAssociatedStreamId(int associatedStreamId) {
68 if (associatedStreamId < 0) {
69 throw new IllegalArgumentException(
70 "Associated-To-Stream-ID cannot be negative: " +
71 associatedStreamId);
72 }
73 this.associatedStreamId = associatedStreamId;
74 return this;
75 }
76
77 @Override
78 public byte priority() {
79 return priority;
80 }
81
82 @Override
83 public SpdySynStreamFrame setPriority(byte priority) {
84 if (priority < 0 || priority > 7) {
85 throw new IllegalArgumentException(
86 "Priority must be between 0 and 7 inclusive: " + priority);
87 }
88 this.priority = priority;
89 return this;
90 }
91
92 @Override
93 public boolean isUnidirectional() {
94 return unidirectional;
95 }
96
97 @Override
98 public SpdySynStreamFrame setUnidirectional(boolean unidirectional) {
99 this.unidirectional = unidirectional;
100 return this;
101 }
102
103 @Override
104 public String toString() {
105 StringBuilder buf = new StringBuilder()
106 .append(StringUtil.simpleClassName(this))
107 .append("(last: ")
108 .append(isLast())
109 .append("; unidirectional: ")
110 .append(isUnidirectional())
111 .append(')')
112 .append(StringUtil.NEWLINE)
113 .append("--> Stream-ID = ")
114 .append(streamId())
115 .append(StringUtil.NEWLINE);
116 if (associatedStreamId != 0) {
117 buf.append("--> Associated-To-Stream-ID = ")
118 .append(associatedStreamId())
119 .append(StringUtil.NEWLINE);
120 }
121 buf.append("--> Priority = ")
122 .append(priority())
123 .append(StringUtil.NEWLINE)
124 .append("--> Headers:")
125 .append(StringUtil.NEWLINE);
126 appendHeaders(buf);
127
128
129 buf.setLength(buf.length() - StringUtil.NEWLINE.length());
130 return buf.toString();
131 }
132 }