@author shannah
| 10 | * @author shannah |
| 11 | */ |
| 12 | public class StringWriter extends Writer implements Appendable { |
| 13 | |
| 14 | private StringBuffer buf; |
| 15 | |
| 16 | public StringWriter() { |
| 17 | buf = new StringBuffer(); |
| 18 | } |
| 19 | |
| 20 | public StringWriter(int initialSize) { |
| 21 | buf = new StringBuffer(initialSize); |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public void close() throws IOException { |
| 26 | |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public void flush() throws IOException { |
| 31 | |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public void write(char[] cbuf, int off, int len) throws IOException { |
| 36 | buf.append(cbuf, off, len); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void write(String str, int off, int len) throws IOException { |
| 41 | buf.append(str, off, off + len); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void write(int c) throws IOException { |
| 46 | buf.append((char)c); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void write(String str) throws IOException { |
| 51 | buf.append(str); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void write(char[] cbuf) throws IOException { |
| 56 | buf.append(cbuf); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public String toString() { |
| 61 | return buf.toString(); |
| 62 | } |
| 63 | |
| 64 | public StringBuffer getBuffer() { |
| 65 | return buf; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | public StringWriter append(char c) { |
nothing calls this directly
no outgoing calls
no test coverage detected