Mercurial Hosting > luan
comparison src/org/eclipse/jetty/server/HttpWriter.java @ 985:8fef34f665e7
remove HttpOutput
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 16 Oct 2016 23:47:23 -0600 |
parents | 7b0fa315e835 |
children |
comparison
equal
deleted
inserted
replaced
984:7b0fa315e835 | 985:8fef34f665e7 |
---|---|
25 import org.eclipse.jetty.http.HttpGenerator; | 25 import org.eclipse.jetty.http.HttpGenerator; |
26 import org.eclipse.jetty.util.ByteArrayOutputStream2; | 26 import org.eclipse.jetty.util.ByteArrayOutputStream2; |
27 import org.eclipse.jetty.util.StringUtil; | 27 import org.eclipse.jetty.util.StringUtil; |
28 | 28 |
29 /** OutputWriter. | 29 /** OutputWriter. |
30 * A writer that can wrap a {@link HttpOutput} stream and provide | 30 * A writer that can wrap a {@link AbstractHttpConnection.Output} stream and provide |
31 * character encodings. | 31 * character encodings. |
32 * | 32 * |
33 * The UTF-8 encoding is done by this class and no additional | 33 * The UTF-8 encoding is done by this class and no additional |
34 * buffers or Writers are used. | 34 * buffers or Writers are used. |
35 * The UTF-8 code was inspired by http://javolution.org | 35 * The UTF-8 code was inspired by http://javolution.org |
40 | 40 |
41 private static final int WRITE_CONV = 0; | 41 private static final int WRITE_CONV = 0; |
42 private static final int WRITE_ISO1 = 1; | 42 private static final int WRITE_ISO1 = 1; |
43 private static final int WRITE_UTF8 = 2; | 43 private static final int WRITE_UTF8 = 2; |
44 | 44 |
45 private final HttpOutput _out; | 45 private final AbstractHttpConnection.Output _out; |
46 private int _writeMode; | 46 private int _writeMode; |
47 private int _surrogate; | 47 private int _surrogate; |
48 | 48 |
49 public HttpWriter(HttpOutput out) | 49 public HttpWriter(AbstractHttpConnection.Output out) |
50 { | 50 { |
51 _out = out; | 51 _out = out; |
52 _surrogate = 0; // AS lastUTF16CodePoint | 52 _surrogate = 0; // AS lastUTF16CodePoint |
53 } | 53 } |
54 | 54 |
106 } | 106 } |
107 | 107 |
108 @Override | 108 @Override |
109 public void write (char[] s,int offset, int length) throws IOException | 109 public void write (char[] s,int offset, int length) throws IOException |
110 { | 110 { |
111 HttpOutput out = _out; | |
112 | |
113 while (length > 0) | 111 while (length > 0) |
114 { | 112 { |
115 out._bytes.reset(); | 113 _out._bytes.reset(); |
116 int chars = length>MAX_OUTPUT_CHARS?MAX_OUTPUT_CHARS:length; | 114 int chars = length>MAX_OUTPUT_CHARS?MAX_OUTPUT_CHARS:length; |
117 | 115 |
118 switch (_writeMode) | 116 switch (_writeMode) |
119 { | 117 { |
120 case WRITE_CONV: | 118 case WRITE_CONV: |
125 } | 123 } |
126 break; | 124 break; |
127 | 125 |
128 case WRITE_ISO1: | 126 case WRITE_ISO1: |
129 { | 127 { |
130 byte[] buffer=out._bytes.getBuf(); | 128 byte[] buffer = _out._bytes.getBuf(); |
131 int bytes=out._bytes.getCount(); | 129 int bytes = _out._bytes.getCount(); |
132 | 130 |
133 if (chars>buffer.length-bytes) | 131 if (chars>buffer.length-bytes) |
134 chars=buffer.length-bytes; | 132 chars=buffer.length-bytes; |
135 | 133 |
136 for (int i = 0; i < chars; i++) | 134 for (int i = 0; i < chars; i++) |
137 { | 135 { |
138 int c = s[offset+i]; | 136 int c = s[offset+i]; |
139 buffer[bytes++]=(byte)(c<256?c:'?'); // ISO-1 and UTF-8 match for 0 - 255 | 137 buffer[bytes++]=(byte)(c<256?c:'?'); // ISO-1 and UTF-8 match for 0 - 255 |
140 } | 138 } |
141 if (bytes>=0) | 139 if (bytes>=0) |
142 out._bytes.setCount(bytes); | 140 _out._bytes.setCount(bytes); |
143 | 141 |
144 break; | 142 break; |
145 } | 143 } |
146 | 144 |
147 case WRITE_UTF8: | 145 case WRITE_UTF8: |
148 { | 146 { |
149 byte[] buffer=out._bytes.getBuf(); | 147 byte[] buffer = _out._bytes.getBuf(); |
150 int bytes=out._bytes.getCount(); | 148 int bytes = _out._bytes.getCount(); |
151 | 149 |
152 if (bytes+chars>buffer.length) | 150 if (bytes+chars>buffer.length) |
153 chars=buffer.length-bytes; | 151 chars=buffer.length-bytes; |
154 | 152 |
155 for (int i = 0; i < chars; i++) | 153 for (int i = 0; i < chars; i++) |
268 chars=i+1; | 266 chars=i+1; |
269 break; | 267 break; |
270 } | 268 } |
271 } | 269 } |
272 } | 270 } |
273 out._bytes.setCount(bytes); | 271 _out._bytes.setCount(bytes); |
274 break; | 272 break; |
275 } | 273 } |
276 default: | 274 default: |
277 throw new IllegalStateException(); | 275 throw new IllegalStateException(); |
278 } | 276 } |
279 | 277 |
280 out._bytes.writeTo(out); | 278 _out._bytes.writeTo(_out); |
281 length-=chars; | 279 length-=chars; |
282 offset+=chars; | 280 offset+=chars; |
283 } | 281 } |
284 } | 282 } |
285 | 283 |