JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / unused / com / stevesoft / pat / wrap / WriterWrap.java
1 //
2 // This software is now distributed according to
3 // the Lesser Gnu Public License.  Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
5 // the details.
6 //    -- Happy Computing!
7 //
8 package com.stevesoft.pat.wrap;
9
10 import java.io.*;
11
12 import com.stevesoft.pat.*;
13
14 /**
15  * Allows the outcome of a replaceAll() or replaceFirst() to be directed to a
16  * Writer rather than a String.
17  * <p>
18  * The method toStringLike() cannot work, however. This means that the return
19  * value of replaceAll() will be null if this Object is used as the
20  * StringBufferLike.
21  */
22 public class WriterWrap implements BasicStringBufferLike
23 {
24   Writer w;
25
26   public WriterWrap(Writer w)
27   {
28     this.w = w;
29   }
30
31   public void appendChar(char c)
32   {
33     try
34     {
35       w.write((int) c);
36     } catch (IOException ioe)
37     {
38     }
39   }
40
41   public void appendStr(String s)
42   {
43     try
44     {
45       w.write(s);
46     } catch (IOException ioe)
47     {
48     }
49   }
50
51   /** This operation can't really be done. */
52   public StringLike toStringLike()
53   {
54     return null;
55   }
56
57   public Object unwrap()
58   {
59     return w;
60   }
61 }