1 16 package org.mortbay.util; 17 import java.io.IOException ; 18 import java.io.Writer ; 19 20 21 22 27 public class StringBufferWriter extends Writer 28 { 29 30 private StringBuffer _buffer; 31 32 33 35 public StringBufferWriter() 36 { 37 _buffer=new StringBuffer (); 38 } 39 40 41 44 public StringBufferWriter(StringBuffer buffer) 45 { 46 _buffer=buffer; 47 } 48 49 50 public void setStringBuffer(StringBuffer buffer) 51 { 52 _buffer=buffer; 53 } 54 55 56 public StringBuffer getStringBuffer() 57 { 58 return _buffer; 59 } 60 61 62 public void write(char c) 63 throws IOException 64 { 65 _buffer.append(c); 66 } 67 68 69 public void write(char[] ca) 70 throws IOException 71 { 72 _buffer.append(ca); 73 } 74 75 76 77 public void write(char[] ca,int offset, int length) 78 throws IOException 79 { 80 _buffer.append(ca,offset,length); 81 } 82 83 84 public void write(String s) 85 throws IOException 86 { 87 _buffer.append(s); 88 } 89 90 91 public void write(String s,int offset, int length) 92 throws IOException 93 { 94 for (int i=0;i<length;i++) 95 _buffer.append(s.charAt(offset+i)); 96 } 97 98 99 public void flush() 100 {} 101 102 103 public void reset() 104 { 105 _buffer.setLength(0); 106 } 107 108 109 public void close() 110 {} 111 112 } 113 | Popular Tags |