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  
11  public class AppendingToAnObjectOutputStream {
12  	
13  	@ExpectWarning("IO")
14  	public static void appendObject1(File f, Object o) throws FileNotFoundException, IOException {
15  		ObjectOutputStream out = new ObjectOutputStream (new FileOutputStream(f, true));
16  		out.writeObject(o);
17  		out.close();
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  	@ExpectWarning("IO")
26  	public static void appendObject3(String f, Object o) throws FileNotFoundException, IOException {
27  		ObjectOutputStream out = new ObjectOutputStream (new FileOutputStream(f, true));
28  		out.writeObject(o);
29  		out.close();
30  	}
31  	@ExpectWarning("IO")
32  	public static void appendObject4(String f, Object o) throws FileNotFoundException, IOException {
33  		ObjectOutputStream out = new ObjectOutputStream (new BufferedOutputStream(new FileOutputStream(f, true)));
34  		out.writeObject(o);
35  		out.close();
36  	}
37  }