3737 */
3838public class BoundedInputStream extends InputStream {
3939
40- /** the wrapped input stream */
41- private final InputStream in ;
40+ /** The wrapped input stream */
41+ private final InputStream inputStream ;
4242
43- /** the max length to provide */
44- private final long max ;
43+ /** The max length to provide */
44+ private final long maxLength ;
4545
46- /** the number of bytes already returned */
46+ /** The number of bytes already returned */
4747 private long pos ;
4848
49- /** the marked position */
49+ /** The marked position */
5050 private long mark = EOF ;
5151
52- /** flag if close should be propagated */
52+ /** Flag if close should be propagated */
5353 private boolean propagateClose = true ;
5454
5555 /**
@@ -66,25 +66,25 @@ public BoundedInputStream(final InputStream in) {
6666 * Creates a new {@link BoundedInputStream} that wraps the given input
6767 * stream and limits it to a certain size.
6868 *
69- * @param in The wrapped input stream
70- * @param size The maximum number of bytes to return
69+ * @param inputStream The wrapped input stream
70+ * @param maxLength The maximum number of bytes to return
7171 */
72- public BoundedInputStream (final InputStream in , final long size ) {
72+ public BoundedInputStream (final InputStream inputStream , final long maxLength ) {
7373 // Some badly designed methods - e.g. the servlet API - overload length
7474 // such that "-1" means stream finished
75- this .max = size ;
76- this .in = in ;
75+ this .maxLength = maxLength ;
76+ this .inputStream = inputStream ;
7777 }
7878
7979 /**
8080 * {@inheritDoc}
8181 */
8282 @ Override
8383 public int available () throws IOException {
84- if (max >= 0 && pos >= max ) {
84+ if (maxLength >= 0 && pos >= maxLength ) {
8585 return 0 ;
8686 }
87- return in .available ();
87+ return inputStream .available ();
8888 }
8989
9090 /**
@@ -95,7 +95,7 @@ public int available() throws IOException {
9595 @ Override
9696 public void close () throws IOException {
9797 if (propagateClose ) {
98- in .close ();
98+ inputStream .close ();
9999 }
100100 }
101101
@@ -117,7 +117,7 @@ public boolean isPropagateClose() {
117117 */
118118 @ Override
119119 public synchronized void mark (final int readlimit ) {
120- in .mark (readlimit );
120+ inputStream .mark (readlimit );
121121 mark = pos ;
122122 }
123123
@@ -127,7 +127,7 @@ public synchronized void mark(final int readlimit) {
127127 */
128128 @ Override
129129 public boolean markSupported () {
130- return in .markSupported ();
130+ return inputStream .markSupported ();
131131 }
132132
133133 /**
@@ -139,10 +139,10 @@ public boolean markSupported() {
139139 */
140140 @ Override
141141 public int read () throws IOException {
142- if (max >= 0 && pos >= max ) {
142+ if (maxLength >= 0 && pos >= maxLength ) {
143143 return EOF ;
144144 }
145- final int result = in .read ();
145+ final int result = inputStream .read ();
146146 pos ++;
147147 return result ;
148148 }
@@ -170,11 +170,11 @@ public int read(final byte[] b) throws IOException {
170170 */
171171 @ Override
172172 public int read (final byte [] b , final int off , final int len ) throws IOException {
173- if (max >= 0 && pos >= max ) {
173+ if (maxLength >= 0 && pos >= maxLength ) {
174174 return EOF ;
175175 }
176- final long maxRead = max >= 0 ? Math .min (len , max - pos ) : len ;
177- final int bytesRead = in .read (b , off , (int ) maxRead );
176+ final long maxRead = maxLength >= 0 ? Math .min (len , maxLength - pos ) : len ;
177+ final int bytesRead = inputStream .read (b , off , (int ) maxRead );
178178
179179 if (bytesRead == EOF ) {
180180 return EOF ;
@@ -190,7 +190,7 @@ public int read(final byte[] b, final int off, final int len) throws IOException
190190 */
191191 @ Override
192192 public synchronized void reset () throws IOException {
193- in .reset ();
193+ inputStream .reset ();
194194 pos = mark ;
195195 }
196196
@@ -215,8 +215,8 @@ public void setPropagateClose(final boolean propagateClose) {
215215 */
216216 @ Override
217217 public long skip (final long n ) throws IOException {
218- final long toSkip = max >= 0 ? Math .min (n , max - pos ) : n ;
219- final long skippedBytes = in .skip (toSkip );
218+ final long toSkip = maxLength >= 0 ? Math .min (n , maxLength - pos ) : n ;
219+ final long skippedBytes = inputStream .skip (toSkip );
220220 pos += skippedBytes ;
221221 return skippedBytes ;
222222 }
@@ -227,6 +227,6 @@ public long skip(final long n) throws IOException {
227227 */
228228 @ Override
229229 public String toString () {
230- return in .toString ();
230+ return inputStream .toString ();
231231 }
232232}
0 commit comments