You can do something like following :
OutputStream output = new OutputStream()
{
private StringBuilder string = new StringBuilder();
@Override
public void write(int x) throws IOException {
this.string.append((char) x );
}
public String toString(){
return this.string.toString();
}
};