1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.io.bio;
20
21 import java.io.ByteArrayInputStream;
22 import java.io.ByteArrayOutputStream;
23
24 import org.eclipse.jetty.util.StringUtil;
25
26
27
28
29
30
31
32 public class StringEndPoint extends StreamEndPoint
33 {
34 String _encoding=StringUtil.__UTF8;
35 ByteArrayInputStream _bin = new ByteArrayInputStream(new byte[0]);
36 ByteArrayOutputStream _bout = new ByteArrayOutputStream();
37
38 public StringEndPoint()
39 {
40 super(null,null);
41 _in=_bin;
42 _out=_bout;
43 }
44
45 public StringEndPoint(String encoding)
46 {
47 this();
48 if (encoding!=null)
49 _encoding=encoding;
50 }
51
52 public void setInput(String s)
53 {
54 try
55 {
56 byte[] bytes = s.getBytes(_encoding);
57 _bin=new ByteArrayInputStream(bytes);
58 _in=_bin;
59 _bout = new ByteArrayOutputStream();
60 _out=_bout;
61 _ishut=false;
62 _oshut=false;
63 }
64 catch(Exception e)
65 {
66 throw new IllegalStateException(e.toString());
67 }
68 }
69
70 public String getOutput()
71 {
72 try
73 {
74 String s = new String(_bout.toByteArray(),_encoding);
75 _bout.reset();
76 return s;
77 }
78 catch(final Exception e)
79 {
80 throw new IllegalStateException(_encoding)
81 {
82 {initCause(e);}
83 };
84 }
85 }
86
87
88
89
90 public boolean hasMore()
91 {
92 return _bin.available()>0;
93 }
94 }