1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.http2;
17
18 import java.nio.charset.Charset;
19
20
21
22
23
24
25
26
27
28
29 public abstract class AbstractHttpData implements HttpData {
30
31 protected final String name;
32
33 protected long definedSize = 0;
34
35 protected long size = 0;
36
37 protected Charset charset = HttpCodecUtil.DEFAULT_CHARSET;
38
39 protected boolean completed = false;
40
41 public AbstractHttpData(String name, Charset charset, long size)
42 throws NullPointerException, IllegalArgumentException {
43 if (name == null) {
44 throw new NullPointerException("name");
45 }
46 name = name.trim();
47 if (name.length() == 0) {
48 throw new IllegalArgumentException("empty name");
49 }
50
51 for (int i = 0; i < name.length(); i ++) {
52 char c = name.charAt(i);
53 if (c > 127) {
54 throw new IllegalArgumentException(
55 "name contains non-ascii character: " + name);
56 }
57
58
59 switch (c) {
60 case '=':
61 case ',':
62 case ';':
63 case ' ':
64 case '\t':
65 case '\r':
66 case '\n':
67 case '\f':
68 case 0x0b:
69 throw new IllegalArgumentException(
70 "name contains one of the following prohibited characters: " +
71 "=,; \\t\\r\\n\\v\\f: " + name);
72 }
73 }
74 this.name = name;
75 if (charset != null) {
76 setCharset(charset);
77 }
78 definedSize = size;
79 }
80
81 public String getName() {
82 return name;
83 }
84
85 public boolean isCompleted() {
86 return completed;
87 }
88
89 public Charset getCharset() {
90 return charset;
91 }
92
93 public void setCharset(Charset charset) {
94 if (charset == null) {
95 throw new NullPointerException("charset");
96 }
97 this.charset = charset;
98 }
99
100 public long length() {
101 return size;
102 }
103 }