1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.recovery;
15
16 import java.io.*;
17 import java.nio.channels.FileChannel;
18
19 public class ResilientFileOutputStream extends ResilientOutputStreamBase {
20
21 private File file;
22 private FileOutputStream fos;
23
24 public ResilientFileOutputStream(File file, boolean append, long bufferSize) throws FileNotFoundException {
25 this.file = file;
26 fos = new FileOutputStream(file, append);
27 this.os = new BufferedOutputStream(fos, (int) bufferSize);
28 this.presumedClean = true;
29 }
30
31 public FileChannel getChannel() {
32 if (os == null) {
33 return null;
34 }
35 return fos.getChannel();
36 }
37
38 public File getFile() {
39 return file;
40 }
41
42 @Override
43 String getDescription() {
44 return "file [" + file + "]";
45 }
46
47 @Override
48 OutputStream openNewOutputStream() throws IOException {
49
50 fos = new FileOutputStream(file, true);
51 return new BufferedOutputStream(fos);
52 }
53
54 @Override
55 public String toString() {
56 return "c.q.l.c.recovery.ResilientFileOutputStream@" + System.identityHashCode(this);
57 }
58
59 }