From e3f294c09061fb5c1d0d14c0d012daf5befdd482 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Sat, 20 May 2023 15:36:24 +0100 Subject: [PATCH] Add the ability to change the clampedLength in LengthClampedInputStream. --- .../calmnet/stream/LengthClampedInputStream.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/com/captainalm/lib/calmnet/stream/LengthClampedInputStream.java b/src/com/captainalm/lib/calmnet/stream/LengthClampedInputStream.java index c99eb20..f834889 100644 --- a/src/com/captainalm/lib/calmnet/stream/LengthClampedInputStream.java +++ b/src/com/captainalm/lib/calmnet/stream/LengthClampedInputStream.java @@ -130,4 +130,17 @@ public class LengthClampedInputStream extends FilterInputStream { if (!closed) closed = true; super.close(); } + + /** + * Sets a new clamped length value. + * This is the maximum number of bytes that can be read from the stream. + * + * @param clampedLength The new clamped length value. + * @throws IllegalArgumentException clampedLength is less than 0. + */ + public synchronized void setClampedLength(int clampedLength) { + if (clampedLength < 0) throw new IllegalArgumentException("clampedLength is less than 0"); + if (closed) return; + this.clampedLength = clampedLength; + } }