-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickStart.java
62 lines (42 loc) · 1.26 KB
/
QuickStart.java
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 com.github.downgoon.bsf.example;
import java.io.IOException;
import com.github.downgoon.bsf.BigSequenceFile;
public class QuickStart {
public static void main(String[] args) throws IOException {
BigSequenceFile bsf = null;
try {
bsf = new BigSequenceFile("/Users/liwei/tmp/bsf/hello.bsf");
bsf.open();
System.out.println("bsf init: " + bsf);
new Thread(new WatchingReader(bsf), "watching-reader").start();
bsf.appendTrunk("abc".getBytes());
System.out.println("bsf after wrting 'abc': " + bsf);
bsf.appendTrunk("def".getBytes());
System.out.println("bsf after wrting 'def': " + bsf);
bsf.appendTrunk("g".getBytes());
System.out.println("bsf after wrting 'g': " + bsf);
} finally {
if (bsf != null) {
bsf.close();
}
}
}
static class WatchingReader implements Runnable {
private BigSequenceFile bsf;
public WatchingReader(BigSequenceFile bsf) {
this.bsf = bsf;
}
@Override
public void run() {
while (true) {
byte[] trunk = bsf.deductTrunk();
System.out.println("\t<<< bsf reading: " + new String(trunk) + " | with meta: " + bsf);
if (trunk == null) {
System.out.println("\t<<< bsf read NULL");
} else {
System.out.println(new String(trunk));
}
}
}
}
}