diff options
Diffstat (limited to 'src/test/java/org/gnunet/util/FilePipeExample.java')
-rw-r--r-- | src/test/java/org/gnunet/util/FilePipeExample.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/java/org/gnunet/util/FilePipeExample.java b/src/test/java/org/gnunet/util/FilePipeExample.java new file mode 100644 index 0000000..94696c9 --- /dev/null +++ b/src/test/java/org/gnunet/util/FilePipeExample.java | |||
@@ -0,0 +1,41 @@ | |||
1 | package org.gnunet.util; | ||
2 | |||
3 | import java.io.File; | ||
4 | import java.io.IOError; | ||
5 | import java.io.IOException; | ||
6 | import java.nio.ByteBuffer; | ||
7 | |||
8 | /** | ||
9 | * ... | ||
10 | * | ||
11 | * @author Florian Dold | ||
12 | */ | ||
13 | public class FilePipeExample { | ||
14 | public static void main(String... args) { | ||
15 | |||
16 | Program.configureLogging("DEBUG", null); | ||
17 | |||
18 | final Scheduler.FilePipe fp = Scheduler.openFilePipe(new File("test.pipe")); | ||
19 | |||
20 | |||
21 | Scheduler.addRead(RelativeTime.FOREVER, fp.getSource(), new Scheduler.Task() { | ||
22 | @Override | ||
23 | public void run(Scheduler.RunContext ctx) { | ||
24 | ByteBuffer b = ByteBuffer.allocate(1); | ||
25 | b.clear(); | ||
26 | try { | ||
27 | fp.getSource().read(b); | ||
28 | } catch (IOException e) { | ||
29 | throw new IOError(e); | ||
30 | } | ||
31 | b.flip(); | ||
32 | System.out.println("got: " + b.get()); | ||
33 | |||
34 | Scheduler.addRead(RelativeTime.FOREVER, fp.getSource(), this); | ||
35 | |||
36 | } | ||
37 | }); | ||
38 | |||
39 | Scheduler.run(); | ||
40 | } | ||
41 | } | ||