source: doc/theses/rob_schluntz/examples/intro/FileOutputStream.java@ 633a642

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 633a642 was 728df66, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

more documentation name changes

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import java.io.IOException;
2import java.io.FileNotFoundException;
3
4public class FileOutputStream implements AutoCloseable {
5 public static int throwOnWrite;
6 public static int throwOnClose;
7 public static int throwOnOpen;
8
9 public static int numWrites;
10 public static int numCloses;
11 public static int numOpens;
12
13 private String filename;
14 private <EX extends Throwable> void doexcept(EX ex, boolean pred) throws EX {
15 if (pred) {
16 System.out.println("Stream: " + filename + " threw exception: " + ex);
17 throw ex;
18 }
19 }
20
21 public FileOutputStream(String filename) throws FileNotFoundException {
22 doexcept(new FileNotFoundException(), throwOnOpen == ++numOpens);
23 System.out.println("Opened file: " + filename);
24 this.filename = filename;
25 }
26 public void write(byte[] bytes) throws IOException {
27 doexcept(new IOException(), throwOnWrite == ++numWrites);
28 System.out.println("wrote message: " + new String(bytes) + " to file: " + filename);
29 }
30 public void close() throws IOException {
31 System.out.println("Closing file: " + filename);
32 filename = null;
33 doexcept(new IOException(), throwOnClose == ++numCloses);
34 }
35 protected void finalize() {
36 if (filename != null) System.out.println("Finalize closing file: " + filename);
37 }
38}
Note: See TracBrowser for help on using the repository browser.