43 import java.nio.charset.*;
51 class StringContent
implements Content {
53 private static Charset ascii = Charset.forName(
"US-ASCII");
56 private String content;
58 StringContent(CharSequence c, String t) {
59 content = c.toString();
60 if (!content.endsWith(
"\n"))
62 type = t +
"; charset=iso-8859-1";
65 StringContent(CharSequence c) {
66 this(c,
"text/plain");
69 StringContent(Exception x) {
70 StringWriter sw =
new StringWriter();
71 x.printStackTrace(
new PrintWriter(sw));
72 type =
"text/plain; charset=iso-8859-1";
73 content = sw.toString();
76 public String type() {
80 private ByteBuffer bb =
null;
82 private void encode() {
84 bb = ascii.encode(CharBuffer.wrap(content));
87 public long length() {
89 return bb.remaining();
92 public void prepare() {
97 public boolean send(ChannelIO cio)
throws IOException {
99 throw new IllegalStateException();
102 return bb.hasRemaining();
105 public void release() throws IOException {