]> WPIA git - gigi.git/blob - lib/jetty/org/eclipse/jetty/server/Iso88591HttpWriter.java
updating jetty to jetty-9.2.16.v2016040
[gigi.git] / lib / jetty / org / eclipse / jetty / server / Iso88591HttpWriter.java
1 //
2 //  ========================================================================
3 //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 //  ------------------------------------------------------------------------
5 //  All rights reserved. This program and the accompanying materials
6 //  are made available under the terms of the Eclipse Public License v1.0
7 //  and Apache License v2.0 which accompanies this distribution.
8 //
9 //      The Eclipse Public License is available at
10 //      http://www.eclipse.org/legal/epl-v10.html
11 //
12 //      The Apache License v2.0 is available at
13 //      http://www.opensource.org/licenses/apache2.0.php
14 //
15 //  You may elect to redistribute this code under either of these licenses.
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 }