Skip to content

Commit 9bc3ef7

Browse files
committed
Added PipedOutputStream example
1 parent d93bd00 commit 9bc3ef7

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.barista.pipedoutputstream;
2+
3+
import java.io.IOException;
4+
import java.io.PipedInputStream;
5+
import java.io.PipedOutputStream;
6+
7+
public class PipedOutputStreamMainTest {
8+
public static void main(String[] args) throws IOException{
9+
//test1();
10+
//test2();
11+
//test3();
12+
//test4();
13+
//test5();
14+
}
15+
16+
public static void test1() throws IOException {
17+
PipedOutputStream pos = new PipedOutputStream(new PipedInputStream());
18+
// I cannot connect if PipedInputStream is provided.
19+
pos.connect(null);
20+
}
21+
22+
public static void test2() throws IOException {
23+
PipedOutputStream pos = new PipedOutputStream(new PipedInputStream());
24+
pos.close();
25+
pos.flush();
26+
}
27+
28+
public static void test3() throws IOException {
29+
PipedOutputStream pos = new PipedOutputStream(new PipedInputStream());
30+
pos.close();
31+
// I cannot write a bit after close.
32+
pos.write(1);
33+
}
34+
35+
public static void test4() throws IOException {
36+
PipedOutputStream pos = new PipedOutputStream(new PipedInputStream());
37+
pos.close();
38+
byte[] x = {1, 2, 3};
39+
// I cannot write bits, offsent, and len after close.
40+
pos.write(x, 2, 3);
41+
}
42+
43+
public static void test5() throws IOException {
44+
PipedOutputStream pos = new PipedOutputStream(new PipedInputStream());
45+
byte[] x = {1, 2, 3};
46+
// I cannot have negative values for arguments.
47+
pos.write(x, -2, -3);
48+
pos.close();
49+
}
50+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.barista.pipedoutputstream;
2+
3+
import java.io.PipedInputStream;
4+
5+
import liquidjava.specification.ExternalRefinementsFor;
6+
import liquidjava.specification.Refinement;
7+
import liquidjava.specification.RefinementAlias;
8+
import liquidjava.specification.StateRefinement;
9+
import liquidjava.specification.StateSet;
10+
11+
@RefinementAlias("Nat(int x) {x >= 0}")
12+
@StateSet({"connected", "created", "closed"})
13+
@ExternalRefinementsFor("java.io.PipedOutputStream")
14+
public interface PipedOutputStreamRefinements {
15+
16+
@StateRefinement(to="connected(this)")
17+
public void PipedOutputStream(PipedInputStream snk);
18+
19+
@StateRefinement(to="created(this)")
20+
public void PipedOutputStream();
21+
22+
@StateRefinement(from="created(this) || closed(this)", to="connected(this)")
23+
public void connect(PipedInputStream snk);
24+
25+
@StateRefinement(from="connected(this)", to="connected(this)")
26+
public void write(int b);
27+
28+
@StateRefinement(from="connected(this)", to="connected(this)")
29+
public void write(byte[] b, @Refinement("Nat(_)") int off, @Refinement("Nat(_)") int len);
30+
31+
// Testing the execution, I can do flush, no exceptions are raised.
32+
public void flush();
33+
34+
@StateRefinement(from="created(this) || connected(this)", to="closed(this)")
35+
public void close();
36+
}

0 commit comments

Comments
 (0)