blob: cfe72c2e7215a18614fe015efc695eaab412799e (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package bjc.utils.ioutils.blocks;
import java.io.IOException;
/**
* A block reader that fires an action before a block is actually read.
*
* @author bjculkin
*
*/
public class TriggeredBlockReader implements BlockReader {
private BlockReader source;
private Runnable action;
/**
* Create a new triggered reader with the specified source/action.
*
* @param source
* The block reader to read blocks from.
*
* @param action
* The action to execute before reading a block.
*/
public TriggeredBlockReader(BlockReader source, Runnable action) {
super();
this.source = source;
this.action = action;
}
@Override
public boolean hasNextBlock() {
action.run();
return source.hasNextBlock();
}
@Override
public Block getBlock() {
return source.getBlock();
}
@Override
public boolean nextBlock() {
return source.nextBlock();
}
@Override
public int getBlockCount() {
return source.getBlockCount();
}
@Override
public void close() throws IOException {
source.close();
}
@Override
public String toString() {
return String.format("TriggeredBlockReader [source=%s]", source);
}
}
|