| Class | Line # | Actions | |||
|---|---|---|---|---|---|
| WriterWrap | 24 | 7 | 7 |
| 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 | 0 | public WriterWrap(Writer w) |
| 29 | { | |
| 30 | 0 | this.w = w; |
| 31 | } | |
| 32 | ||
| 33 | 0 | public void append(char c) |
| 34 | { | |
| 35 | 0 | try |
| 36 | { | |
| 37 | 0 | w.write((int) c); |
| 38 | } catch (IOException ioe) | |
| 39 | { | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | 0 | public void append(String s) |
| 44 | { | |
| 45 | 0 | try |
| 46 | { | |
| 47 | 0 | w.write(s); |
| 48 | } catch (IOException ioe) | |
| 49 | { | |
| 50 | } | |
| 51 | } | |
| 52 | ||
| 53 | /** This operation can't really be done. */ | |
| 54 | 0 | public StringLike toStringLike() |
| 55 | { | |
| 56 | 0 | return null; |
| 57 | } | |
| 58 | ||
| 59 | 0 | public Object unwrap() |
| 60 | { | |
| 61 | 0 | return w; |
| 62 | } | |
| 63 | } |