1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.server;
20
21 import java.io.IOException;
22
23
24
25 public class Iso88591HttpWriter extends HttpWriter
26 {
27
28 public Iso88591HttpWriter(HttpOutput out)
29 {
30 super(out);
31 }
32
33
34 @Override
35 public void write (char[] s,int offset, int length) throws IOException
36 {
37 HttpOutput out = _out;
38 if (length==0 && out.isAllContentWritten())
39 {
40 close();
41 return;
42 }
43
44 if (length==1)
45 {
46 int c=s[offset];
47 out.write(c<256?c:'?');
48 return;
49 }
50
51 while (length > 0)
52 {
53 _bytes.reset();
54 int chars = length>MAX_OUTPUT_CHARS?MAX_OUTPUT_CHARS:length;
55
56 byte[] buffer=_bytes.getBuf();
57 int bytes=_bytes.getCount();
58
59 if (chars>buffer.length-bytes)
60 chars=buffer.length-bytes;
61
62 for (int i = 0; i < chars; i++)
63 {
64 int c = s[offset+i];
65 buffer[bytes++]=(byte)(c<256?c:'?');
66 }
67 if (bytes>=0)
68 _bytes.setCount(bytes);
69
70 _bytes.writeTo(out);
71 length-=chars;
72 offset+=chars;
73 }
74 }
75 }