KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > generators > VelocityWriter


1 package org.objectweb.celtix.tools.generators;
2
3 import java.io.BufferedWriter JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.Writer JavaDoc;
6
7 public class VelocityWriter extends BufferedWriter JavaDoc {
8     
9     private final String JavaDoc newLine = System.getProperty("line.separator");
10
11     public VelocityWriter(Writer JavaDoc out) {
12         super(out);
13     }
14
15     public VelocityWriter(Writer JavaDoc out, int size) {
16         super(out, size);
17     }
18
19     public void write(char[] chars) throws IOException JavaDoc {
20         String JavaDoc str = new String JavaDoc(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 JavaDoc str) throws IOException JavaDoc {
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