2929import java .util .stream .Stream ;
3030
3131import org .apache .commons .io .build .AbstractStreamBuilder ;
32- import org .apache .commons .io .input .BOMInputStream ;
3332
3433/**
3534 * An {@link ObjectInputStream} that's restricted to deserialize a limited set of classes.
@@ -73,18 +72,18 @@ public class ValidatingObjectInputStream extends ObjectInputStream {
7372
7473 // @formatter:off
7574 /**
76- * Builds a new {@link BOMInputStream }.
75+ * Builds a new {@link ValidatingObjectInputStream }.
7776 *
7877 * <h2>Using NIO</h2>
7978 * <pre>{@code
8079 * ValidatingObjectInputStream s = ValidatingObjectInputStream.builder()
81- * .setPath(Paths.get("MyFile.xml "))
80+ * .setPath(Paths.get("MyFile.ser "))
8281 * .get();}
8382 * </pre>
8483 * <h2>Using IO</h2>
8584 * <pre>{@code
8685 * ValidatingObjectInputStream s = ValidatingObjectInputStream.builder()
87- * .setFile(new File("MyFile.xml "))
86+ * .setFile(new File("MyFile.ser "))
8887 * .get();}
8988 * </pre>
9089 *
@@ -115,7 +114,7 @@ public static Builder builder() {
115114 private final List <ClassNameMatcher > rejectMatchers = new ArrayList <>();
116115
117116 /**
118- * Constructs an object to deserialize the specified input stream. At least one accept method needs to be called to specify which classes can be
117+ * Constructs an instance to deserialize the specified input stream. At least one accept method needs to be called to specify which classes can be
119118 * deserialized, as by default no classes are accepted.
120119 *
121120 * @param input an input stream
@@ -128,7 +127,7 @@ public ValidatingObjectInputStream(final InputStream input) throws IOException {
128127 }
129128
130129 /**
131- * Accept the specified classes for deserialization, unless they are otherwise rejected.
130+ * Accepts the specified classes for deserialization, unless they are otherwise rejected.
132131 *
133132 * @param classes Classes to accept
134133 * @return this object
@@ -139,33 +138,33 @@ public ValidatingObjectInputStream accept(final Class<?>... classes) {
139138 }
140139
141140 /**
142- * Accept class names where the supplied ClassNameMatcher matches for deserialization, unless they are otherwise rejected.
141+ * Accepts class names where the supplied ClassNameMatcher matches for deserialization, unless they are otherwise rejected.
143142 *
144- * @param m the matcher to use
145- * @return this object
143+ * @param matcher the class name matcher to <em>accept</em> objects.
144+ * @return this instance.
146145 */
147- public ValidatingObjectInputStream accept (final ClassNameMatcher m ) {
148- acceptMatchers .add (m );
146+ public ValidatingObjectInputStream accept (final ClassNameMatcher matcher ) {
147+ acceptMatchers .add (matcher );
149148 return this ;
150149 }
151150
152151 /**
153- * Accept class names that match the supplied pattern for deserialization, unless they are otherwise rejected.
152+ * Accepts class names that match the supplied pattern for deserialization, unless they are otherwise rejected.
154153 *
155- * @param pattern standard Java regexp
156- * @return this object
154+ * @param pattern a Pattern for compiled regular expression.
155+ * @return this instance.
157156 */
158157 public ValidatingObjectInputStream accept (final Pattern pattern ) {
159158 acceptMatchers .add (new RegexpClassNameMatcher (pattern ));
160159 return this ;
161160 }
162161
163162 /**
164- * Accept the wildcard specified classes for deserialization, unless they are otherwise rejected.
163+ * Accepts the wildcard specified classes for deserialization, unless they are otherwise rejected.
165164 *
166165 * @param patterns Wildcard file name patterns as defined by {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String)
167- * FilenameUtils.wildcardMatch}
168- * @return this object
166+ * FilenameUtils.wildcardMatch}.
167+ * @return this instance.
169168 */
170169 public ValidatingObjectInputStream accept (final String ... patterns ) {
171170 Stream .of (patterns ).map (WildcardClassNameMatcher ::new ).forEach (acceptMatchers ::add );
@@ -175,8 +174,8 @@ public ValidatingObjectInputStream accept(final String... patterns) {
175174 /**
176175 * Checks that the class name conforms to requirements.
177176 *
178- * @param name The class name
179- * @throws InvalidClassException when a non-accepted class is encountered
177+ * @param name The class name to test.
178+ * @throws InvalidClassException Thrown when a rejected or non-accepted class is found.
180179 */
181180 private void checkClassName (final String name ) throws InvalidClassException {
182181 // Reject has precedence over accept
@@ -202,52 +201,52 @@ private void checkClassName(final String name) throws InvalidClassException {
202201 * Called to throw {@link InvalidClassException} if an invalid class name is found during deserialization. Can be overridden, for example to log those class
203202 * names.
204203 *
205- * @param className name of the invalid class
206- * @throws InvalidClassException if the specified class is not allowed
204+ * @param className name of the invalid class.
205+ * @throws InvalidClassException Thrown with a message containing the class name.
207206 */
208207 protected void invalidClassNameFound (final String className ) throws InvalidClassException {
209208 throw new InvalidClassException ("Class name not accepted: " + className );
210209 }
211210
212211 /**
213- * Reject the specified classes for deserialization, even if they are otherwise accepted.
212+ * Rejects the specified classes for deserialization, even if they are otherwise accepted.
214213 *
215- * @param classes Classes to reject
216- * @return this object
214+ * @param classes Classes to reject.
215+ * @return this instance.
217216 */
218217 public ValidatingObjectInputStream reject (final Class <?>... classes ) {
219218 Stream .of (classes ).map (c -> new FullClassNameMatcher (c .getName ())).forEach (rejectMatchers ::add );
220219 return this ;
221220 }
222221
223222 /**
224- * Reject class names where the supplied ClassNameMatcher matches for deserialization, even if they are otherwise accepted.
223+ * Rejects class names where the supplied ClassNameMatcher matches for deserialization, even if they are otherwise accepted.
225224 *
226- * @param m the matcher to use
227- * @return this object
225+ * @param matcher a class name matcher to <em>reject</em> objects.
226+ * @return this instance.
228227 */
229- public ValidatingObjectInputStream reject (final ClassNameMatcher m ) {
230- rejectMatchers .add (m );
228+ public ValidatingObjectInputStream reject (final ClassNameMatcher matcher ) {
229+ rejectMatchers .add (matcher );
231230 return this ;
232231 }
233232
234233 /**
235- * Reject class names that match the supplied pattern for deserialization, even if they are otherwise accepted.
234+ * Rejects class names that match the supplied pattern for deserialization, even if they are otherwise accepted.
236235 *
237- * @param pattern standard Java regexp
238- * @return this object
236+ * @param pattern a Pattern for compiled regular expression.
237+ * @return this instance.
239238 */
240239 public ValidatingObjectInputStream reject (final Pattern pattern ) {
241240 rejectMatchers .add (new RegexpClassNameMatcher (pattern ));
242241 return this ;
243242 }
244243
245244 /**
246- * Reject the wildcard specified classes for deserialization, even if they are otherwise accepted.
245+ * Rejects the wildcard specified classes for deserialization, even if they are otherwise accepted.
247246 *
248- * @param patterns Wildcard file name patterns as defined by {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String)
247+ * @param patterns An array of wildcard file name patterns as defined by {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String)
249248 * FilenameUtils.wildcardMatch}
250- * @return this object
249+ * @return this instance.
251250 */
252251 public ValidatingObjectInputStream reject (final String ... patterns ) {
253252 Stream .of (patterns ).map (WildcardClassNameMatcher ::new ).forEach (rejectMatchers ::add );
0 commit comments