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