1 package de.webman.generator; 2 3 import java.io.*; 4 5 12 public class WrappingWriter extends FilterWriter 13 { 14 protected String prefix; 15 protected int prefixLen; 16 17 protected String postfix; 18 protected int postfixLen; 19 20 private String newline; 21 22 26 public WrappingWriter(Writer out) 27 { 28 super(out); 29 newline = System.getProperty("line.separator"); 30 } 31 32 35 public void setPrefix(String prefix) 36 { 37 if (prefix == null) { 38 prefix = ""; 39 } 40 41 this.prefix = prefix; 42 prefixLen = prefix.length(); 43 } 44 45 46 49 public void setPostfix(String postfix) 50 { 51 if (postfix == null) { 52 postfix = ""; 53 } 54 55 this.postfix = postfix; 56 postfixLen = postfix.length(); 57 } 58 59 63 public void write(String str, int off, int len) throws IOException 64 { 65 if (str == null || str.equals("") || str.equals(newline) ) 66 return; 67 68 super.write(prefix + str + postfix, off, prefixLen + len + postfixLen); 69 } 70 } 71 72 | Popular Tags |