X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FBufferedOutputStream.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FBufferedOutputStream.java;h=8b74ae162d2b58bf90040650bf7d02312134fece;hb=c8ce09c4dc57142f94afcdc290dd79c4bddf7820;hp=6f600eba7c06384db6f254ed8a89642257641156;hpb=8e76f6ab13a8a4a651f2518b6c91d5e6424c7922;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/streams/BufferedOutputStream.java b/src/be/nikiroo/utils/streams/BufferedOutputStream.java index 6f600eb..8b74ae1 100644 --- a/src/be/nikiroo/utils/streams/BufferedOutputStream.java +++ b/src/be/nikiroo/utils/streams/BufferedOutputStream.java @@ -22,13 +22,22 @@ public class BufferedOutputStream extends OutputStream { protected byte[] buffer; /** An End-Of-File (or buffer, here) marker. */ protected boolean eof; + /** The actual under-laying stream. */ + protected OutputStream out; + /** The number of bytes written to the under-laying stream. */ + protected long bytesWritten; + /** + * Can bypass the flush process for big writes (will directly write to the + * under-laying buffer if the array to write is > the internal buffer + * size). + *

+ * By default, this is true. + */ + protected boolean bypassFlush = true; private boolean closed; - private OutputStream out; private int openCounter; - private long bytesWritten; - /** * Create a new {@link BufferedInputStream} that wraps the given * {@link InputStream}. @@ -165,19 +174,23 @@ public class BufferedOutputStream extends OutputStream { } /** - * Flush the {@link BufferedOutputStream}, and optionally the under-laying - * stream, too. + * Flush the {@link BufferedOutputStream}, write the current buffered data + * to (and optionally also flush) the under-laying stream. + *

+ * If {@link BufferedOutputStream#bypassFlush} is false, all writes to the + * under-laying stream are done in this method. * * @param includingSubStream * also flush the under-laying stream * @throws IOException * in case of I/O error */ - private void flush(boolean includingSubStream) throws IOException { + protected void flush(boolean includingSubStream) throws IOException { out.write(buffer, start, stop - start); bytesWritten += (stop - start); start = 0; stop = 0; + if (includingSubStream) { out.flush(); }