This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
commit 422edc83619e23380526a032b8ffe502734a324c Author: Gary Gregory <[email protected]> AuthorDate: Sun Jul 26 14:46:12 2026 -0400 No need to nest --- .../fileupload2/core/DeferrableOutputStream.java | 54 +++++++++++----------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/DeferrableOutputStream.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/DeferrableOutputStream.java index 3c03b6bb..43847850 100644 --- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/DeferrableOutputStream.java +++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/DeferrableOutputStream.java @@ -205,7 +205,7 @@ public class DeferrableOutputStream extends OutputStream { } else { this.threshold = threshold; } - longThreshold = (long) threshold; + longThreshold = threshold; this.pathSupplier = pathSupplier; this.listener = listener; checkThreshold(0); @@ -234,27 +234,26 @@ public class DeferrableOutputStream extends OutputStream { state = State.initialized; return baos; } - } else { - switch (state) { - case initialized: - case opened: - final int bytesWritten = baos.size(); - if ((long) bytesWritten + (long) numberOfIncomingBytes >= longThreshold) { - return persist(); - } - if (numberOfIncomingBytes > 0) { - state = State.opened; - } - return baos; - case persisted: - // Do nothing, we're staying in the current state. - return out; - case closed: - // Do nothing, we're staying in the current state. - return null; - default: - throw illegalStateError(); + } + switch (state) { + case initialized: + case opened: + final int bytesWritten = baos.size(); + if ((long) bytesWritten + (long) numberOfIncomingBytes >= longThreshold) { + return persist(); } + if (numberOfIncomingBytes > 0) { + state = State.opened; + } + return baos; + case persisted: + // Do nothing, we're staying in the current state. + return out; + case closed: + // Do nothing, we're staying in the current state. + return null; + default: + throw illegalStateError(); } } @@ -305,15 +304,14 @@ public class DeferrableOutputStream extends OutputStream { * failed. */ public InputStream getInputStream() throws IOException { - if (state == State.closed) { - if (bytes != null) { - return new ByteArrayInputStream(bytes); - } else { - return Files.newInputStream(path); - } - } else { + if (state != State.closed) { throw new IllegalStateException("This stream isn't yet closed."); } + if (bytes != null) { + return new ByteArrayInputStream(bytes); + } else { + return Files.newInputStream(path); + } } /**
