aboutsummaryrefslogtreecommitdiff
path: root/test/org/gnunet/util/FilePipeExample.java
blob: 94696c9fe13a16a47f7cc0812f5a932ccfa29498 (plain) (blame)
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
package org.gnunet.util;

import java.io.File;
import java.io.IOError;
import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * ...
 *
 * @author Florian Dold
 */
public class FilePipeExample {
    public static void main(String... args) {

        Program.configureLogging("DEBUG", null);

        final Scheduler.FilePipe fp = Scheduler.openFilePipe(new File("test.pipe"));


        Scheduler.addRead(RelativeTime.FOREVER, fp.getSource(), new Scheduler.Task() {
            @Override
            public void run(Scheduler.RunContext ctx) {
                ByteBuffer b = ByteBuffer.allocate(1);
                b.clear();
                try {
                    fp.getSource().read(b);
                } catch (IOException e) {
                    throw new IOError(e);
                }
                b.flip();
                System.out.println("got: " + b.get());

                Scheduler.addRead(RelativeTime.FOREVER, fp.getSource(), this);

            }
        });

        Scheduler.run();
    }
}