Skip to content

Commit 5158978

Browse files
committed
ZipOutputStream Refinements
1 parent 8ddeabf commit 5158978

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.zipOutputStream;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
import java.nio.charset.Charset;
6+
import java.util.zip.ZipEntry;
7+
8+
import liquidjava.specification.ExternalRefinementsFor;
9+
import liquidjava.specification.Refinement;
10+
import liquidjava.specification.RefinementAlias;
11+
import liquidjava.specification.StateRefinement;
12+
import liquidjava.specification.StateSet;
13+
14+
@RefinementAlias("Positive(int v) { v >= 0 }")
15+
@RefinementAlias("Level(int v) { 0 <= v && v <= 9 }")
16+
@StateSet({"open", "ready", "closed"})
17+
@ExternalRefinementsFor("java.util.zip.ZipOutputStream")
18+
public interface ZipOutputStreamRefinements {
19+
20+
@StateRefinement(to="open(this)")
21+
public void ZipOutputStream(OutputStream out);
22+
23+
@StateRefinement(to="open(this)")
24+
public void ZipOutputStream(OutputStream out, Charset charset);
25+
26+
@StateRefinement(from="open(this)", to="open(this)")
27+
public void setComment(/*@Refinement("'length(_) <= 65535'")*/String comment);
28+
29+
@StateRefinement(from="open(this)", to="open(this)")
30+
public void setMethod(@Refinement("Positive(_)") int method); // too many different possible values, none of them are negative though
31+
32+
@StateRefinement(from="open(this)", to="open(this)")
33+
public void setLevel(@Refinement("Level(_)") int level);
34+
35+
@StateRefinement(from="open(this)", to="ready(this)")
36+
public void putNextEntry(ZipEntry e) throws IOException;
37+
38+
@StateRefinement(from="ready(this)", to="open(this)")
39+
public void closeEntry() throws IOException;
40+
41+
@StateRefinement(from="ready(this)", to="ready(this)")
42+
public void write(byte[] b, @Refinement("Positive(_)") int off, @Refinement("Positive(_)") int len) throws IOException;
43+
44+
@StateRefinement(from="ready(this)", to="ready(this)")
45+
public void finish() throws IOException;
46+
47+
@StateRefinement(from="!closed(this)", to="closed(this)")
48+
public void close() throws IOException;
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.zipOutputStream;
2+
3+
import java.io.FileOutputStream;
4+
import java.util.zip.ZipOutputStream;
5+
6+
public class ZipOutputStreamTests {
7+
8+
void testWritingToClosedStream() throws Exception {
9+
FileOutputStream fos = new FileOutputStream("file");
10+
ZipOutputStream zos = new ZipOutputStream(fos);
11+
zos.setMethod(8);
12+
zos.setLevel(5);
13+
zos.close();
14+
zos.write(null, 0, 0);
15+
}
16+
17+
void testParametricRefinements() throws Exception {
18+
FileOutputStream fos = new FileOutputStream("file");
19+
ZipOutputStream zos = new ZipOutputStream(fos);
20+
zos.setLevel(10);
21+
}
22+
}

0 commit comments

Comments
 (0)