View Javadoc
1   import java.io.BufferedOutputStream;
2   import java.io.File;
3   import java.io.FileNotFoundException;
4   import java.io.FileOutputStream;
5   import java.io.IOException;
6   import java.io.ObjectOutputStream;
7   
8   import edu.umd.cs.findbugs.annotations.ExpectWarning;
9   
10  public class AppendingToAnObjectOutputStream {
11  
12      @ExpectWarning("IO")
13      public static void appendObject1(File f, Object o) throws FileNotFoundException, IOException {
14          ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f, true));
15          out.writeObject(o);
16          out.close();
17      }
18  
19      @ExpectWarning("IO")
20      public static void appendObject2(File f, Object o) throws FileNotFoundException, IOException {
21          ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f, true)));
22          out.writeObject(o);
23          out.close();
24      }
25  
26      @ExpectWarning("IO")
27      public static void appendObject3(String f, Object o) throws FileNotFoundException, IOException {
28          ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f, true));
29          out.writeObject(o);
30          out.close();
31      }
32  
33      @ExpectWarning("IO")
34      public static void appendObject4(String f, Object o) throws FileNotFoundException, IOException {
35          ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f, true)));
36          out.writeObject(o);
37          out.close();
38      }
39  }