1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package net.sf.eos.io;
16
17 import java.io.FilterWriter;
18 import java.io.IOException;
19 import java.io.Writer;
20
21
22
23
24
25
26
27 public class NewlineReplaceWriter extends FilterWriter {
28
29
30
31
32
33 public NewlineReplaceWriter(final Writer out) {
34 super(out);
35 }
36
37
38
39
40 @Override
41 public void write(final int c) throws IOException {
42 if (c == '\n' || c == '\r') {
43 this.out.write(' ');
44 } else {
45 this.out.write(c);
46 }
47 }
48
49
50
51
52 @Override
53 public void write(final char cbuf[],
54 final int off,
55 final int len) throws IOException {
56 final char[] nbuf = new char[len];
57
58 for (int i = 0, j = off; i < len; j++, i++) {
59 char c = cbuf[j];
60 if (c == '\n' || c == '\r') {
61 c = ' ';
62 }
63 nbuf[i] = c;
64 }
65 this.out.write(nbuf, 0, nbuf.length);
66 }
67
68
69
70
71 @Override
72 public void write(final String str,
73 final int off,
74 final int len) throws IOException {
75 final String sub = str.substring(off, (off+ len));
76 final char[] cs = sub.toCharArray();
77 write(cs, 0, cs.length);
78 }
79 }