Add the ability to change the clampedLength in LengthClampedInputStream.

This commit is contained in:
Captain ALM 2023-05-20 15:36:24 +01:00
parent aab4fdd8fa
commit e3f294c090
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -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;
}
}