Skip to content

Commit d4c40de

Browse files
committed
Javadoc
Show how to limit the amount of data read into a ValidatingObjectInputStream by using a BoundedInputStream.
1 parent 8259e6f commit d4c40de

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

src/main/java/org/apache/commons/io/serialization/ValidatingObjectInputStream.java

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,37 +84,37 @@
8484
* </p>
8585
* <pre>{@code
8686
* // Deserializing with a size limit successfully
87-
* try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
88-
* ValidatingObjectInputStream vois = ValidatingObjectInputStream.builder()
89-
* .accept(HashMap.class, Number.class, Integer.class)
90-
* .setInputStream(BoundedInputStream.builder()
91-
* .setMaxCount(10_000)
92-
* .setOnMaxCount((remains, count) -> {
93-
* throw new IllegalArgumentException("Input exceeds limit.");
94-
* })
95-
* .setInputStream(bais)
96-
* .get())
97-
* .get()) {
98-
* // String.class is automatically accepted
99-
* final HashMap<String, Integer> map2 = (HashMap<String, Integer>) vois.readObject();
100-
* assertEquals(map1, map2);
101-
* }
102-
* // Deserializing with a size limit reaching the limit
103-
* try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
104-
* ValidatingObjectInputStream vois = ValidatingObjectInputStream.builder()
105-
* .accept(HashMap.class, Number.class, Integer.class)
106-
* .setInputStream(BoundedInputStream.builder()
107-
* .setMaxCount(10)
108-
* .setOnMaxCount((remains, count) -> {
109-
* throw new IllegalArgumentException("Input exceeds limit.");
110-
* })
111-
* .setInputStream(bais)
112-
* .get())
113-
* .get()) {
114-
* // String.class is automatically accepted
115-
* final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> vois.readObject());
116-
* assertEquals("Input exceeds limit.", e.getMessage());
117-
* }
87+
* try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
88+
* ValidatingObjectInputStream vois = ValidatingObjectInputStream.builder()
89+
* .accept(HashMap.class, Number.class, Integer.class)
90+
* .setInputStream(BoundedInputStream.builder()
91+
* .setMaxCount(10_000)
92+
* .setOnMaxCount((remains, count) -> {
93+
* throw new IllegalArgumentException("Input exceeds limit.");
94+
* })
95+
* .setInputStream(bais)
96+
* .get())
97+
* .get()) {
98+
* // String.class is automatically accepted
99+
* final HashMap<String, Integer> map2 = (HashMap<String, Integer>) vois.readObject();
100+
* assertEquals(map1, map2);
101+
* }
102+
* // Deserializing with a size limit reaching the limit
103+
* try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
104+
* ValidatingObjectInputStream vois = ValidatingObjectInputStream.builder()
105+
* .accept(HashMap.class, Number.class, Integer.class)
106+
* .setInputStream(BoundedInputStream.builder()
107+
* .setMaxCount(10)
108+
* .setOnMaxCount((remains, count) -> {
109+
* throw new IllegalArgumentException("Input exceeds limit.");
110+
* })
111+
* .setInputStream(bais)
112+
* .get())
113+
* .get()) {
114+
* // String.class is automatically accepted
115+
* final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> vois.readObject());
116+
* assertEquals("Input exceeds limit.", e.getMessage());
117+
* }
118118
* }</pre>
119119
* @since 2.5
120120
*/

0 commit comments

Comments
 (0)