Skip to content

Commit ba0a76c

Browse files
committed
feat: introduce BufferedInputStream refinement specifications for safe state transitions
1 parent 262849d commit ba0a76c

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.barista.bufferedinputstream;
2+
3+
import java.io.InputStream;
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("Positive(int x) {x >= 0}")
12+
@StateSet({"open", "closed", "marked"})
13+
@ExternalRefinementsFor("java.io.BufferedInputStream")
14+
public interface BufferedInputStreamRefinements {
15+
16+
@StateRefinement(to="open(this)")
17+
public void BufferedInputStream(InputStream in);
18+
19+
@StateRefinement(to="open(this)")
20+
public void BufferedInputStream(InputStream in, @Refinement("Positive(_)") int size);
21+
22+
@StateRefinement(from="open(this)", to="open(this)")
23+
@StateRefinement(from="marked(this)", to="marked(this)")
24+
public int read();
25+
26+
@StateRefinement(from="open(this)", to="open(this)")
27+
@StateRefinement(from="marked(this)", to="marked(this)")
28+
public int read(byte[] b,
29+
@Refinement("Positive(_)") int off,
30+
@Refinement("Positive(_)") int len);
31+
32+
@StateRefinement(from="open(this)", to="open(this)")
33+
@StateRefinement(from="marked(this)", to="marked(this)")
34+
public long skip(@Refinement("Positive(_)") long n);
35+
36+
@StateRefinement(from="marked(this)", to="marked(this)")
37+
public int available();
38+
39+
@StateRefinement(from="open(this)", to="marked(this)")
40+
@StateRefinement(from="marked(this)", to="marked(this)")
41+
public void mark(@Refinement("Positive(_)") int readlimit);
42+
43+
@StateRefinement(from="marked(this)", to="marked(this)")
44+
public int reset();
45+
46+
@StateRefinement(from="open(this)", to="open(this)")
47+
@StateRefinement(from="marked(this)", to="marked(this)")
48+
public boolean markSupported();
49+
50+
@StateRefinement(from="open(this)", to="closed(this)")
51+
@StateRefinement(from="marked(this)", to="closed(this)")
52+
public boolean close();
53+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.barista.bufferedinputstream;
2+
3+
import java.io.BufferedInputStream;
4+
import java.io.IOException;
5+
6+
public class BufferedInputStreamTest {
7+
public void test1() throws IOException {
8+
BufferedInputStream x = new BufferedInputStream(null);
9+
x.close();
10+
x.available();
11+
}
12+
13+
public void test2() throws IOException {
14+
BufferedInputStream x = new BufferedInputStream(null);
15+
x.available();
16+
}
17+
}

0 commit comments

Comments
 (0)