You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Reads bytes up to a maximum length, if its count goes above that, it stops.
29
+
* Reads bytes up to a maximum count and stops once reached.
29
30
* <p>
30
-
* This is useful to wrap {@code ServletInputStream}s. The {@code ServletInputStream} will block if you try to read content from it that isn't there, because it
31
-
* doesn't know whether the content hasn't arrived yet or whether the content has finished. So, one of these, initialized with the {@code Content-Length} sent
32
-
* in the {@code ServletInputStream}'s header, will stop it blocking, providing it's been sent with a correct content length.
31
+
* To build an instance, see {@link AbstractBuilder}.
33
32
* </p>
34
33
* <p>
35
-
* To build an instance, use {@link Builder}.
34
+
* By default, a {@link BoundedInputStream} is <em>unbound</em>; so make sure to call {@link AbstractBuilder#setMaxCount(long)}.
36
35
* </p>
37
-
*
36
+
* <p>
37
+
* You can find out how many bytes this stream has seen so far by calling {@link BoundedInputStream#getCount()}. This value reflects bytes read and skipped.
38
+
* </p>
39
+
* <h2>Using a ServletInputStream</h2>
40
+
* <p>
41
+
* A {@code ServletInputStream} can block if you try to read content that isn't there
42
+
* because it doesn't know whether the content hasn't arrived yet or whether the content has finished. Initialize an {@link BoundedInputStream} with the
43
+
* {@code Content-Length} sent in the {@code ServletInputStream}'s header, this stop it from blocking, providing it's been sent with a correct content
44
+
* length in the first place.
45
+
* </p>
46
+
* <h2>Using NIO</h2>
47
+
* <pre>{@code
48
+
* BoundedInputStream s = BoundedInputStream.builder()
49
+
* .setPath(Paths.get("MyFile.xml"))
50
+
* .setMaxCount(1024)
51
+
* .setPropagateClose(false)
52
+
* .get();
53
+
* }
54
+
* </pre>
55
+
* <h2>Using IO</h2>
56
+
* <pre>{@code
57
+
* BoundedInputStream s = BoundedInputStream.builder()
58
+
* .setFile(new File("MyFile.xml"))
59
+
* .setMaxCount(1024)
60
+
* .setPropagateClose(false)
61
+
* .get();
62
+
* }
63
+
* </pre>
64
+
* <h2>Counting Bytes</h2>
65
+
* <p>You can set the running count when building, which is most useful when starting from another stream:
66
+
* <pre>{@code
67
+
* InputStream in = ...;
68
+
* BoundedInputStream s = BoundedInputStream.builder()
* By default, a {@link BoundedInputStream} is <em>unbound</em>; so make sure to call {@link AbstractBuilder#setMaxCount(long)}.
163
+
* </p>
164
+
* <p>
165
+
* You can find out how many bytes this stream has seen so far by calling {@link BoundedInputStream#getCount()}. This value reflects bytes read and skipped.
166
+
* </p>
167
+
* <h2>Using a ServletInputStream</h2>
168
+
* <p>
169
+
* A {@code ServletInputStream} can block if you try to read content that isn't there
170
+
* because it doesn't know whether the content hasn't arrived yet or whether the content has finished. Initialize an {@link BoundedInputStream} with the
171
+
* {@code Content-Length} sent in the {@code ServletInputStream}'s header, this stop it from blocking, providing it's been sent with a correct content
172
+
* length in the first place.
173
+
* </p>
49
174
* <h2>Using NIO</h2>
50
175
* <pre>{@code
51
176
* BoundedInputStream s = BoundedInputStream.builder()
@@ -64,18 +189,24 @@ public class BoundedInputStream extends ProxyInputStream {
64
189
* .get();
65
190
* }
66
191
* </pre>
192
+
* <h2>Counting Bytes</h2>
193
+
* <p>You can set the running count when building, which is most useful when starting from another stream:
194
+
* <pre>{@code
195
+
* InputStream in = ...;
196
+
* BoundedInputStream s = BoundedInputStream.builder()
// Some badly designed methods - e.g. the Servlet API - overload length
178
283
// such that "-1" means stream finished
179
-
this(inputStream, maxCount, true);
284
+
this(inputStream, 0, maxCount, true);
180
285
}
181
286
182
287
/**
183
288
* Constructs a new {@link BoundedInputStream} that wraps the given input stream and limits it to a certain size.
184
289
*
185
290
* @param inputStream The wrapped input stream.
186
-
* @param maxCount The maximum number of bytes to return.
291
+
* @param count The current number of bytes read.
292
+
* @param maxCount The maximum number of bytes to return.
187
293
* @param propagateClose {@code true} if calling {@link #close()} propagates to the {@code close()} method of the underlying stream or {@code false} if it
* @param propagateClose {@code true} if calling {@link #close()} propagates to the {@code close()} method of the underlying stream or {@code false} if it
375
491
* does not.
376
-
* @deprecated Use {@link Builder#setPropagateClose(boolean)}.
492
+
* @deprecated Use {@link AbstractBuilder#setPropagateClose(boolean)}.
0 commit comments