import java.io.OutputStream;\r
\r
public class StringBuilderOutputStream extends OutputStream {\r
- private StringBuilder buf;\r
+ private StringBuilder buf;\r
\r
\r
/**\r
* size.\r
*/\r
public StringBuilderOutputStream() {\r
- buf = new StringBuilder();\r
+ buf = new StringBuilder();\r
}\r
\r
/**\r
* size.\r
*/\r
public StringBuilderOutputStream(StringBuilder sb) {\r
- buf = sb;\r
+ buf = sb;\r
}\r
\r
/**\r
* If <tt>initialSize</tt> is negative\r
*/\r
public StringBuilderOutputStream(int initialSize) {\r
- if (initialSize < 0) {\r
- throw new IllegalArgumentException("Negative buffer size");\r
- }\r
- buf = new StringBuilder(initialSize);\r
+ if (initialSize < 0) {\r
+ throw new IllegalArgumentException("Negative buffer size");\r
+ }\r
+ buf = new StringBuilder(initialSize);\r
}\r
\r
/**\r
* Write a single character.\r
*/\r
public void write(int c) {\r
- buf.append((byte) c);\r
+ buf.append((byte) c);\r
}\r
\r
/**\r
}\r
\r
@Override\r
- public void write(byte[] b) throws IOException {\r
- buf.append(new String(b));\r
- }\r
+ public void write(byte[] b) throws IOException {\r
+ buf.append(new String(b));\r
+ }\r
\r
- /**\r
+ /**\r
* Write a string.\r
*/\r
public void write(String str) {\r
- buf.append(str);\r
+ buf.append(str);\r
}\r
\r
/**\r
* @param len Number of characters to write\r
*/\r
public void write(String str, int off, int len) {\r
- buf.append(str,off,len);\r
+ buf.append(str,off,len);\r
}\r
\r
public StringBuilderOutputStream append(CharSequence csq) {\r
- if (csq == null) {\r
- write("null");\r
- } else {\r
- for(int i = 0;i<csq.length();++i) {\r
- buf.append(csq.charAt(i));\r
- }\r
- }\r
- return this;\r
+ if (csq == null) {\r
+ write("null");\r
+ } else {\r
+ for (int i = 0;i<csq.length();++i) {\r
+ buf.append(csq.charAt(i));\r
+ }\r
+ }\r
+ return this;\r
}\r
\r
public StringBuilderOutputStream append(CharSequence csq, int start, int end) {\r
- CharSequence cs = (csq == null ? "null" : csq);\r
- return append(cs.subSequence(start, end));\r
+ CharSequence cs = (csq == null ? "null" : csq);\r
+ return append(cs.subSequence(start, end));\r
}\r
\r
/**\r
* @since 1.5\r
*/\r
public StringBuilderOutputStream append(byte c) {\r
- buf.append(c);\r
- return this;\r
+ buf.append(c);\r
+ return this;\r
}\r
\r
/**\r
* Return the buffer's current value as a string.\r
*/\r
public String toString() {\r
- return buf.toString();\r
+ return buf.toString();\r
}\r
\r
/**\r
* @return StringBuffer holding the current buffer value.\r
*/\r
public StringBuilder getBuffer() {\r
- return buf;\r
+ return buf;\r
}\r
\r
public void reset() {\r
- buf.setLength(0);\r
+ buf.setLength(0);\r
}\r
\r
- @Override\r
- public void flush() throws IOException {\r
- }\r
+ @Override\r
+ public void flush() throws IOException {\r
+ }\r
\r
- @Override\r
- public void close() throws IOException {\r
- }\r
+ @Override\r
+ public void close() throws IOException {\r
+ }\r
\r
}\r