github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

adamw / jsr308-typestate-checker

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: 80894c9

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

JSR308 Typestate Checker — Read more

  cancel

http://www.warski.org/typestate.html

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Fixing bugs, adding InputStream example 
adamw (author)
Tue Apr 14 09:10:24 -0700 2009
commit  80894c97ce345bf833a7df6fb9079ec66d7f0c89
tree    2788747f1b0e04a57f0582398f71915ae603ff75
parent  2193f552fa5ac47366df554d0dc0cb6601d986d9
jsr308-typestate-checker / example / src / checkers / typestate / ioexample / Example2.java example/src/checkers/typestate/ioexample/Example2.java
100644 48 lines (41 sloc) 1.528 kb
edit raw blame history
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
42
43
44
45
46
47
48
package checkers.typestate.ioexample;
 
import java.io.InputStream;
import java.io.IOException;
 
import static checkers.typestate.ioexample.InputStreamStates.*;
 
/**
* Reading from stream with a recovery function.
* @author Adam Warski (adam at warski dot org)
*/
public class Example2 {
/**
* Reads the first byte of the input stream.
* @param stream Stream from which to read the byte.
* @param numberOfRetries Number of times, which the read should be retries, in case of exceptions.
* @return The first byte of the stream.
* @throws IOException When the first byte couldn't be read in the specified number of retries.
*/
public int readRetry(@Open InputStream stream, int numberOfRetries) throws IOException {
try {
// Looping and trying to read from the stream the specified number of times - 1.
while (numberOfRetries > 1) {
try {
return stream.read();
} catch (IOException e) {
numberOfRetries--;
 
// Recovering the stream and trying again.
recover(stream);
}
}
 
// Here the state of "stream" is "@Open" for sure:
// - if no exception is thrown, the state doesn't change
// - if one is thrown, then the stream is recovered
 
// Trying to read one last time. If this throws an exception - the method will just throw it.
return stream.read();
} finally {
stream.close();
}
}
 
private void recover(@InputStreamError(after = Open.class, onException = InputStreamError.class) InputStream stream) throws IOException {
// Do some magic.
}
}
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server