--- /dev/null
+package net.jaekl.qd.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+
+public class OutputStreamMock extends OutputStream {
+ public interface Listener {
+ public void onWrite(int b);
+ }
+
+ ByteArrayOutputStream m_baos;
+ Listener m_listener;
+
+ public OutputStreamMock() {
+ m_baos = new ByteArrayOutputStream();
+ m_listener = null;
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ m_baos.write(b);
+ if (null != m_listener) {
+ m_listener.onWrite(b);
+ }
+ }
+
+ public byte[] mock_getContent() {
+ return m_baos.toByteArray();
+ }
+
+ public String mock_getContent(Charset charset)
+ {
+ try {
+ return m_baos.toString(charset.name());
+ }
+ catch (UnsupportedEncodingException exc) {
+ // Really, this should not happen
+ throw new RuntimeException(exc);
+ }
+ }
+
+ public void mock_setListener(Listener listener) {
+ m_listener = listener;
+ }
+}