Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / 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.IOException;
11 import java.io.Writer;
12
13 import com.stevesoft.pat.BasicStringBufferLike;
14 import com.stevesoft.pat.StringLike;
15
16 /**
17  * Allows the outcome of a replaceAll() or replaceFirst() to be directed to a
18  * Writer rather than a String.
19  * <p>
20  * The method toStringLike() cannot work, however. This means that the return
21  * value of replaceAll() will be null if this Object is used as the
22  * StringBufferLike.
23  */
24 public class WriterWrap implements BasicStringBufferLike
25 {
26   Writer w;
27
28   public WriterWrap(Writer w)
29   {
30     this.w = w;
31   }
32
33   public void append(char c)
34   {
35     try
36     {
37       w.write((int) c);
38     } catch (IOException ioe)
39     {
40     }
41   }
42
43   public void append(String s)
44   {
45     try
46     {
47       w.write(s);
48     } catch (IOException ioe)
49     {
50     }
51   }
52
53   /** This operation can't really be done. */
54   public StringLike toStringLike()
55   {
56     return null;
57   }
58
59   public Object unwrap()
60   {
61     return w;
62   }
63 }