View Javadoc
1   package obligation;
2   
3   import java.io.FileInputStream;
4   import java.io.IOException;
5   import java.io.InputStream;
6   
7   import javax.annotation.WillClose;
8   
9   import edu.umd.cs.findbugs.annotations.NoWarning;
10  
11  /**
12   * Test to see if WillClose annotations are understood.
13   */
14  public class UsesWillCloseAnnotation {
15  	@NoWarning("OBL")
16  	public void ok(String filename) throws IOException {
17  		InputStream in = new FileInputStream(filename);
18  		try {
19  			int c;
20  			c = in.read();
21  			System.out.println(c);
22  		} finally {
23  			cleanup(in);
24  		}
25  	}
26  	
27  	
28  	public void cleanup(@WillClose InputStream in) {
29  		try {
30  			in.close();
31  		} catch (IOException e) {
32  			// ignore
33  		}
34  	}
35  }