-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterWriter.java
More file actions
executable file
·40 lines (31 loc) · 911 Bytes
/
Copy pathFilterWriter.java
File metadata and controls
executable file
·40 lines (31 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.IOException;
import java.io.Writer;
import java.util.function.BiPredicate;
public class FilterWriter extends Writer{
private Writer writer;
private BiPredicate<Character, Character> pred;
private char previous;
public FilterWriter(Writer writer, BiPredicate<Character, Character> pred, char prev) {
this.writer = writer;
this.pred = pred;
this.previous = prev;
}
@Override
public void write(char[] data, int off, int len) throws IOException {
for (int i = off; i < off + len; i++){
char c = data[i];
if (pred.test(previous, c)){
writer.write(c);
previous = c;
}
}
}
@Override
public void flush() throws IOException {
writer.flush();
}
@Override
public void close() throws IOException {
writer.close();
}
}