Repository: commons-compress
Updated Branches:
  refs/heads/master 5b3ff035f -> bbe4d51f7


preparations for COMPRESS-409


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/bbe4d51f
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/bbe4d51f
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/bbe4d51f

Branch: refs/heads/master
Commit: bbe4d51f7bbd50e9f878e5c884501856c5e6388c
Parents: 5b3ff03
Author: Stefan Bodewig <[email protected]>
Authored: Sun Oct 8 18:19:11 2017 +0200
Committer: Stefan Bodewig <[email protected]>
Committed: Sun Oct 8 18:19:11 2017 +0200

----------------------------------------------------------------------
 .../utils/FixedLengthBlockOutputStream.java       | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/bbe4d51f/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
 
b/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
index 6c93f34..ffe0e3f 100644
--- 
a/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStream.java
@@ -169,18 +169,26 @@ public class FixedLengthBlockOutputStream extends 
OutputStream implements Writab
         return !closed.get();
     }
 
+    /**
+     * Potentialy pads and then writes the block to the underlying stream.
+     * @throws IOException if writing fails
+     */
+    public void flushBlock() throws IOException {
+        if (buffer.position() != 0) {
+            padBlock();
+            writeBlock();
+        }
+    }
+
     @Override
     public void close() throws IOException {
         if (closed.compareAndSet(false, true)) {
-            if (buffer.position() != 0) {
-                padLastBlock();
-                writeBlock();
-            }
+            flushBlock();
             out.close();
         }
     }
 
-    private void padLastBlock() {
+    private void padBlock() {
         buffer.order(ByteOrder.nativeOrder());
         int bytesToWrite = buffer.remaining();
         if (bytesToWrite > 8) {

Reply via email to