package com.tutego.insel.solutions.io;

import java.io.*;

public class SnifferOutputStream extends FilterOutputStream
{
  private StringBuffer written = new StringBuffer( 1024 );

  public SnifferOutputStream( OutputStream out )
  {
    super( out );
  }

  public void reset()
  {
    written = new StringBuffer( 1024 );
  }

  public synchronized void write( int b ) throws IOException
  {
    out.write( b );
    written.append( (char) b );
  }

  public synchronized String getContent() throws IOException
  {
    return written.toString();
  }

  public static void main( String[] args ) throws IOException
  {
    SnifferOutputStream sos = new SnifferOutputStream ( new FileOutputStream("alois.txt") );
    DataOutputStream dos = new DataOutputStream( sos );
    dos.writeChars ( "Hallo Leute\n" );
    dos.writeUTF( "Hallo Leute" );
    System.out.println( sos.getContent() );
  }
}
