|
Programmer's Notebook |
All computer source code presented on this page, unless it includes attribution to another author, is provided by Ed Halley under the Artistic License. Use such code freely and without any expectation of support. I would like to know if you make anything cool with the code, or need questions answered.
python/ bindings.py boards.py buzz.py cache.py cards.py constraints.py csql.py english.py getopts.py gizmos.py goals.py improv.py interpolations.py namespaces.py nihongo.py nodes.py octalplus.py patterns.py persist.py physics.py pids.py pieces.py quizzes.py recipes.py relays.py romaji.py ropen.py sheets.py strokes.py subscriptions.py svgbuild.py testing.py things.py timing.py ucsv.py useful.py uuid.py vectors.py weighted.py java/ CSVReader.java CSVWriter.java GlobFilenameFilter.java RegexFilenameFilter.java StringBufferOutputStream.java ThreadSet.java Throttle.java TracingThread.java Utf8ConsoleTest.java droid/ ArrangeViewsTouchListener.java DownloadFileTask.java perl/ CVQM.pm Kana.pm Typo.pm cxx/ CCache.h equalish.cpp |
Download StringBufferOutputStream.java
|
package cc.halley.java.util; import java.io.IOException; import java.io.OutputStream; /** * An OutputStream that collects all of the output into a new StringBuffer. * * We use StringBuffer instead of StringBuilder, for thread safety. */ public class StringBufferOutputStream extends OutputStream { protected StringBuffer buffer = new StringBuffer(); protected boolean closed = false; synchronized public void write(int b) throws IOException { if (closed) throw new IOException("StringBufferOutputStream already closed."); buffer.append((char)b); } public void write(byte[] b) throws IOException { write(b, 0, b.length); } public void write(byte[] b, int off, int len) throws IOException { for (int i = off; i < off+len; i++) write((int)b[i]); } public void close() throws IOException { if (closed) throw new IOException("StringBufferOutputStream already closed."); closed = true; } public void flush() throws IOException { if (closed) throw new IOException("StringBufferOutputStream already closed."); } public boolean equals(Object obj) { if (obj instanceof String) return toString().equals(obj); return super.equals(obj); } synchronized public int hashCode() { return buffer.hashCode(); } synchronized public String toString() { return buffer.toString(); } } |
|
Contact Ed Halley by email at
ed@halley.cc. Text, code, layout and artwork are Copyright © 1996-2013 Ed Halley. Copying in whole or in part, with author attribution, is expressly allowed. Any references to trademarks are illustrative and are controlled by their respective owners. |
|