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.io.IOException;
19
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.jboss.netty.buffer.ChannelBuffers;
22
23
24
25
26
27
28
29
30
31 public class DiskAttribute extends AbstractDiskHttpData implements Attribute {
32 public static String baseDirectory = null;
33
34 public static boolean deleteOnExitTemporaryFile = true;
35
36 public static String prefix = "Attr_";
37
38 public static String postfix = ".att";
39
40
41
42
43
44 public DiskAttribute(String name) {
45 super(name, HttpCodecUtil.DEFAULT_CHARSET, 0);
46 }
47
48
49
50
51
52
53
54
55 public DiskAttribute(String name, String value)
56 throws NullPointerException, IllegalArgumentException, IOException {
57 super(name, HttpCodecUtil.DEFAULT_CHARSET, 0);
58 setValue(value);
59 }
60
61 public HttpDataType getHttpDataType() {
62 return HttpDataType.Attribute;
63 }
64
65 public String getValue() throws IOException {
66 byte [] bytes = get();
67 return new String(bytes, charset);
68 }
69
70 public void setValue(String value) throws IOException {
71 if (value == null) {
72 throw new NullPointerException("value");
73 }
74 byte [] bytes = value.getBytes(charset);
75 ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(bytes);
76 if (definedSize > 0) {
77 definedSize = buffer.readableBytes();
78 }
79 setContent(buffer);
80 }
81
82 @Override
83 public void addContent(ChannelBuffer buffer, boolean last) throws IOException {
84 int localsize = buffer.readableBytes();
85 if (definedSize > 0 && definedSize < size + localsize) {
86 definedSize = size + localsize;
87 }
88 super.addContent(buffer, last);
89 }
90 @Override
91 public int hashCode() {
92 return getName().hashCode();
93 }
94
95 @Override
96 public boolean equals(Object o) {
97 if (!(o instanceof Attribute)) {
98 return false;
99 }
100 Attribute attribute = (Attribute) o;
101 return getName().equalsIgnoreCase(attribute.getName());
102 }
103
104 public int compareTo(InterfaceHttpData arg0) {
105 if (!(arg0 instanceof Attribute)) {
106 throw new ClassCastException("Cannot compare " + getHttpDataType() +
107 " with " + arg0.getHttpDataType());
108 }
109 return compareTo((Attribute) arg0);
110 }
111
112 public int compareTo(Attribute o) {
113 return getName().compareToIgnoreCase(o.getName());
114 }
115
116 @Override
117 public String toString() {
118 try {
119 return getName() + "=" + getValue();
120 } catch (IOException e) {
121 return getName() + "=IoException";
122 }
123 }
124
125 protected boolean deleteOnExit() {
126 return deleteOnExitTemporaryFile;
127 }
128
129 protected String getBaseDirectory() {
130 return baseDirectory;
131 }
132
133 protected String getDiskFilename() {
134 return getName()+postfix;
135 }
136
137 protected String getPostfix() {
138 return postfix;
139 }
140
141 protected String getPrefix() {
142 return prefix;
143 }
144 }