File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
metafacture-io/src/main/java/org/metafacture/io Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public class ByteStreamFileWriter extends DefaultObjectReceiver<byte[]> {
24
24
25
25
private Supplier <File > fileNameSupplier ;
26
26
private boolean appendIfFileExists ;
27
+ private boolean flushAfterWrite ;
27
28
28
29
private OutputStream outputStream ;
29
30
@@ -62,6 +63,23 @@ public void setAppendIfFileExists(boolean appendIfFileExists) {
62
63
this .appendIfFileExists = appendIfFileExists ;
63
64
}
64
65
66
+ /**
67
+ * Controls whether the output stream is flushed after each write
68
+ * operation in {@link #process(byte[])}.
69
+ * <p>
70
+ * The default value is {@code false}.
71
+ * <p>
72
+ * This property can be changed anytime during processing. It becomes
73
+ * effective on the next invocation of {@link #process(byte[])}.
74
+ *
75
+ * @param flushAfterWrite true if the output stream should be flushed
76
+ * after every write.
77
+ */
78
+ public void setFlushAfterWrite (boolean flushAfterWrite ) {
79
+
80
+ this .flushAfterWrite = flushAfterWrite ;
81
+ }
82
+
65
83
/**
66
84
* Writes {@code bytes} to file.
67
85
*
@@ -74,6 +92,9 @@ public void process(final byte[] bytes) {
74
92
ensureOpenStream ();
75
93
try {
76
94
outputStream .write (bytes );
95
+ if (flushAfterWrite ) {
96
+ outputStream .flush ();
97
+ }
77
98
78
99
} catch (IOException e ) {
79
100
throw new WriteFailed ("Error while writing bytes to output stream" , e );
You can’t perform that action at this time.
0 commit comments