This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 30da70772 Refactor duplicate code
30da70772 is described below

commit 30da70772ce91d16420f7510f07da968a111b6b5
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Apr 27 09:41:42 2024 -0400

    Refactor duplicate code
---
 .../archivers/ar/ArArchiveOutputStream.java        | 25 +++++++++++-----------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
index a0c87795f..fe0bf6cb9 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
@@ -59,6 +59,15 @@ public class ArArchiveOutputStream extends 
ArchiveOutputStream<ArArchiveEntry> {
         this.out = out;
     }
 
+    /**
+     * @throws IOException
+     */
+    private void checkFinished() throws IOException {
+        if (finished) {
+            throw new IOException("Stream has already been finished");
+        }
+    }
+
     /**
      * Calls finish if necessary, and then closes the OutputStream
      */
@@ -76,9 +85,7 @@ public class ArArchiveOutputStream extends 
ArchiveOutputStream<ArArchiveEntry> {
 
     @Override
     public void closeArchiveEntry() throws IOException {
-        if (finished) {
-            throw new IOException("Stream has already been finished");
-        }
+        checkFinished();
         if (prevEntry == null || !haveUnclosedEntry) {
             throw new IOException("No current entry to close");
         }
@@ -90,9 +97,7 @@ public class ArArchiveOutputStream extends 
ArchiveOutputStream<ArArchiveEntry> {
 
     @Override
     public ArArchiveEntry createArchiveEntry(final File inputFile, final 
String entryName) throws IOException {
-        if (finished) {
-            throw new IOException("Stream has already been finished");
-        }
+        checkFinished();
         return new ArArchiveEntry(inputFile, entryName);
     }
 
@@ -103,9 +108,7 @@ public class ArArchiveOutputStream extends 
ArchiveOutputStream<ArArchiveEntry> {
      */
     @Override
     public ArArchiveEntry createArchiveEntry(final Path inputPath, final 
String entryName, final LinkOption... options) throws IOException {
-        if (finished) {
-            throw new IOException("Stream has already been finished");
-        }
+        checkFinished();
         return new ArArchiveEntry(inputPath, entryName, options);
     }
 
@@ -132,9 +135,7 @@ public class ArArchiveOutputStream extends 
ArchiveOutputStream<ArArchiveEntry> {
 
     @Override
     public void putArchiveEntry(final ArArchiveEntry entry) throws IOException 
{
-        if (finished) {
-            throw new IOException("Stream has already been finished");
-        }
+        checkFinished();
         if (prevEntry == null) {
             writeArchiveHeader();
         } else {

Reply via email to