1 package net.jaekl.qd.util;
3 import java.io.ByteArrayOutputStream;
4 import java.io.IOException;
5 import java.io.OutputStream;
6 import java.io.UnsupportedEncodingException;
7 import java.nio.charset.Charset;
9 public class OutputStreamMock extends OutputStream {
10 public interface Listener {
11 public void onWrite(int b);
14 ByteArrayOutputStream m_baos;
17 public OutputStreamMock() {
18 m_baos = new ByteArrayOutputStream();
23 public void write(int b) throws IOException {
25 if (null != m_listener) {
26 m_listener.onWrite(b);
30 public byte[] mock_getContent() {
31 return m_baos.toByteArray();
34 public String mock_getContent(Charset charset)
37 return m_baos.toString(charset.name());
39 catch (UnsupportedEncodingException exc) {
40 // Really, this should not happen
41 throw new RuntimeException(exc);
45 public void mock_setListener(Listener listener) {
46 m_listener = listener;