Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: konspire/common/StringPrintWriter.java


1   // Jason Rohrer
2   // StringPrintWriter.java
3   
4   /**
5   *
6   *  Message propagated by a server when one of its clients disconnects.
7   *
8   *  Created 8-20-2000
9   *  Mods:
10  */
11  
12  package konspire.common;
13  
14  import java.io.PrintWriter;
15  import java.io.StringWriter;
16  
17  
18  /**
19   * A <code>PrintWriter</code> that prints to a <code>String</code>.
20   * Automatic line flushing is enabled by default.
21   * <p>
22   * Note that the implementation is very ugly right now in attempt
23   * to support Java1.1.  In 1.1, the <code>Writer</code> is not accessible
24   * to subclasses because it is private.  Thus, we can't replace the 
25   * writer after calling the superclass constructor, nor can we simply call the 
26   * superclass constructor and pass in our own member writer (because we
27   * can't access member variables before calling the superclass constructor).
28   * So, this implementation keeps a member <code>PrintWriter</code> and 
29   * has wrapper functions for every <code>PrintWriter</code> function.
30   * <p>
31   * This putrid implementation will change once we're doing full-blown 1.2,
32   * because 1.2 makes the underlying <code>Writer</code> accessible to 
33   * subclasses.
34   *
35   * @author Jason Rohrer
36   */
37  public class StringPrintWriter extends PrintWriter {
38    
39    
40    private StringWriter mStringWriter = new StringWriter();
41    private PrintWriter mPrintWriter = new PrintWriter( mStringWriter, true );
42  
43  
44    /**
45     * Constructs a <code>StringPrintWriter</code>.
46     */
47    public StringPrintWriter() {
48      // call the super class constructor, but we won't
49      // actually use the superclass for anything... until we
50      // move completely to Java 1.2
51      super( new StringWriter(), true );
52      }
53    
54    
55    
56    /**
57     * Gets the buffer's current contents as a <code>String</code>.
58     *
59     * @return the buffer's current contents as a <code>String</code>.
60     */ 
61    public String toString() {
62      return mStringWriter.toString();
63      }
64  
65    
66    // These methods all override and wrap PrintWriter methods
67    
68    public boolean checkError() {
69      return mPrintWriter.checkError();
70      }
71    public void close() {
72      mPrintWriter.close();
73      }
74    public void flush() {
75      mPrintWriter.flush();
76      }
77    public void print( boolean inValue ) {
78      mPrintWriter.print( inValue );
79      }
80  
81    public void print( char inValue ) {
82      mPrintWriter.print( inValue );
83      }
84    public void print( char[] inValue ) {
85      mPrintWriter.print( inValue );
86      }
87    public void print( double inValue ) {
88      mPrintWriter.print( inValue );
89      } 
90    public void print( float inValue ) {
91      mPrintWriter.print( inValue );
92      }
93    public void print( int inValue ) {
94      mPrintWriter.print( inValue );
95      } 
96    public void print( long inValue ) {
97      mPrintWriter.print( inValue );
98      }
99    public void print( Object inValue ) {
100     mPrintWriter.print( inValue );
101     }
102   public void print( String inValue ) {
103     mPrintWriter.println( inValue );
104     }
105   public void println() {
106     mPrintWriter.println();
107     }
108   public void println( boolean inValue ) {
109     mPrintWriter.println( inValue );
110     }
111   public void println( char inValue ) {
112     mPrintWriter.println( inValue );
113     }
114   public void println( char[] inValue ) {
115     mPrintWriter.println( inValue );
116     }
117   public void println( double inValue ) {
118     mPrintWriter.println( inValue );
119     } 
120   public void println( float inValue ) {
121     mPrintWriter.println( inValue );
122     }
123   public void println( int inValue ) {
124     mPrintWriter.println( inValue );
125     } 
126   public void println( long inValue ) {
127     mPrintWriter.println( inValue );
128     }
129   public void println( Object inValue ) {
130     mPrintWriter.println( inValue );
131     }
132   public void println( String inValue ) {
133     mPrintWriter.println( inValue );
134     }
135 
136   // don't worry about wrapping protected methods like setError() 
137 
138   public void write( char[] inValue ) {
139      mPrintWriter.write( inValue );
140     }
141   public void write( char[] inValue, int inStart, int inEnd ) {
142     mPrintWriter.write( inValue, inStart, inEnd );
143     }
144   public void write( int inValue ) {
145      mPrintWriter.write( inValue );
146     }
147   public void write( String inValue ) {
148      mPrintWriter.write( inValue );
149     }
150    public void write( String inValue, int inStart, int inEnd ) {
151     mPrintWriter.write( inValue, inStart, inEnd );
152     }
153   
154   // end of wrapper methods
155 
156   }