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