1 package org.objectweb.celtix.tools.generators; 2 3 import java.io.BufferedWriter ; 4 import java.io.IOException ; 5 import java.io.Writer ; 6 7 public class VelocityWriter extends BufferedWriter { 8 9 private final String newLine = System.getProperty("line.separator"); 10 11 public VelocityWriter(Writer out) { 12 super(out); 13 } 14 15 public VelocityWriter(Writer out, int size) { 16 super(out, size); 17 } 18 19 public void write(char[] chars) throws IOException { 20 String str = new String (chars); 21 if (str.indexOf("\r\n") >= 0 && newLine != null) { 22 super.write(str.replaceAll("\r\n", newLine)); 23 return; 24 } else if (str.indexOf("\n") >= 0 && newLine != null) { 25 super.write(str.replaceAll("\n", newLine)); 26 return; 27 } else { 28 super.write(str); 29 } 30 31 } 32 33 34 35 36 public void write(String str) throws IOException { 37 if (str.indexOf("\r\n") >= 0 && newLine != null) { 38 super.write(str.replaceAll("\r\n", newLine)); 39 return; 40 } else if (str.indexOf("\n") >= 0 && newLine != null) { 41 super.write(str.replaceAll("\r\n", newLine)); 42 return; 43 } else { 44 super.write(str); 45 } 46 } 47 48 } 49 | Popular Tags |