KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > lib > TKByteArrayPrintStream


1 /*
2  * $Header: /cvsroot/webman-cms/source/webman/com/teamkonzept/lib/TKByteArrayPrintStream.java,v 1.6 2001/06/11 14:04:38 alex Exp $
3  *
4  */

5 package com.teamkonzept.lib;
6
7 import java.io.*;
8 import org.apache.log4j.Category;
9
10 /**
11  *
12  */

13 public class TKByteArrayPrintStream extends PrintStream
14 {
15     private static final Category cat = Category.getInstance(TKByteArrayPrintStream.class);
16
17     protected ByteArrayOutputStream buffer;
18     protected OutputStream outputStream;
19     
20     public TKByteArrayPrintStream (OutputStream outputStream)
21     {
22         this (new ByteArrayOutputStream(), outputStream);
23     }
24     
25     protected TKByteArrayPrintStream (ByteArrayOutputStream buffer, OutputStream outputStream)
26     {
27         super (buffer);
28         this.buffer = buffer;
29         this.outputStream = outputStream;
30     }
31     
32     public ByteArrayOutputStream buffer () { return buffer; }
33
34     public OutputStream outputStream () { return outputStream; }
35
36     public void flush()
37     {
38         try {
39             if( buffer.size() > 0 ) {
40                 buffer.writeTo( outputStream );
41                 buffer.reset();
42             }
43         }
44         catch( IOException e ) {
45             cat.error( "message: ", e );
46         }
47     }
48 }
49
Popular Tags