|
23 | 23 | import java.io.InvalidClassException; |
24 | 24 | import java.io.ObjectInputStream; |
25 | 25 | import java.io.ObjectStreamClass; |
26 | | -import java.util.ArrayList; |
27 | | -import java.util.List; |
28 | | -import java.util.function.Predicate; |
29 | 26 | import java.util.regex.Pattern; |
30 | | -import java.util.stream.Stream; |
31 | 27 |
|
32 | 28 | import org.apache.commons.io.build.AbstractStreamBuilder; |
33 | 29 |
|
@@ -247,183 +243,6 @@ public Builder setPredicate(final ObjectStreamClassPredicate predicate) { |
247 | 243 |
|
248 | 244 | } |
249 | 245 |
|
250 | | - /** |
251 | | - * A predicate (boolean-valued function) of one argument to accept and reject classes. |
252 | | - * <p> |
253 | | - * The reject list takes precedence over the accept list. |
254 | | - * </p> |
255 | | - * |
256 | | - * @since 2.18.0 |
257 | | - */ |
258 | | - public static class ObjectStreamClassPredicate implements Predicate<ObjectStreamClass> { |
259 | | - |
260 | | - // This is not a Set for now to avoid ClassNameMatchers requiring proper implementations of hashCode() and equals(). |
261 | | - private final List<ClassNameMatcher> acceptMatchers = new ArrayList<>(); |
262 | | - |
263 | | - // This is not a Set for now to avoid ClassNameMatchers requiring proper implementations of hashCode() and equals(). |
264 | | - private final List<ClassNameMatcher> rejectMatchers = new ArrayList<>(); |
265 | | - |
266 | | - /** |
267 | | - * Constructs a new instance. |
268 | | - */ |
269 | | - public ObjectStreamClassPredicate() { |
270 | | - // empty |
271 | | - } |
272 | | - |
273 | | - /** |
274 | | - * Accepts the specified classes for deserialization, unless they are otherwise rejected. |
275 | | - * <p> |
276 | | - * The reject list takes precedence over the accept list. |
277 | | - * </p> |
278 | | - * |
279 | | - * @param classes Classes to accept |
280 | | - * @return this object |
281 | | - */ |
282 | | - public ObjectStreamClassPredicate accept(final Class<?>... classes) { |
283 | | - Stream.of(classes).map(c -> new FullClassNameMatcher(c.getName())).forEach(acceptMatchers::add); |
284 | | - return this; |
285 | | - } |
286 | | - |
287 | | - /** |
288 | | - * Accepts class names where the supplied ClassNameMatcher matches for deserialization, unless they are otherwise rejected. |
289 | | - * <p> |
290 | | - * The reject list takes precedence over the accept list. |
291 | | - * </p> |
292 | | - * |
293 | | - * @param matcher a class name matcher to <em>accept</em> objects. |
294 | | - * @return this instance. |
295 | | - */ |
296 | | - public ObjectStreamClassPredicate accept(final ClassNameMatcher matcher) { |
297 | | - acceptMatchers.add(matcher); |
298 | | - return this; |
299 | | - } |
300 | | - |
301 | | - /** |
302 | | - * Accepts class names that match the supplied pattern for deserialization, unless they are otherwise rejected. |
303 | | - * <p> |
304 | | - * The reject list takes precedence over the accept list. |
305 | | - * </p> |
306 | | - * |
307 | | - * @param pattern a Pattern for compiled regular expression. |
308 | | - * @return this instance. |
309 | | - */ |
310 | | - public ObjectStreamClassPredicate accept(final Pattern pattern) { |
311 | | - acceptMatchers.add(new RegexpClassNameMatcher(pattern)); |
312 | | - return this; |
313 | | - } |
314 | | - |
315 | | - /** |
316 | | - * Accepts the wildcard specified classes for deserialization, unless they are otherwise rejected. |
317 | | - * <p> |
318 | | - * The reject list takes precedence over the accept list. |
319 | | - * </p> |
320 | | - * |
321 | | - * @param patterns Wildcard file name patterns as defined by {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String) |
322 | | - * FilenameUtils.wildcardMatch} |
323 | | - * @return this instance. |
324 | | - */ |
325 | | - public ObjectStreamClassPredicate accept(final String... patterns) { |
326 | | - Stream.of(patterns).map(WildcardClassNameMatcher::new).forEach(acceptMatchers::add); |
327 | | - return this; |
328 | | - } |
329 | | - |
330 | | - /** |
331 | | - * Rejects the specified classes for deserialization, even if they are otherwise accepted. |
332 | | - * <p> |
333 | | - * The reject list takes precedence over the accept list. |
334 | | - * </p> |
335 | | - * |
336 | | - * @param classes Classes to reject |
337 | | - * @return this instance. |
338 | | - */ |
339 | | - public ObjectStreamClassPredicate reject(final Class<?>... classes) { |
340 | | - Stream.of(classes).map(c -> new FullClassNameMatcher(c.getName())).forEach(rejectMatchers::add); |
341 | | - return this; |
342 | | - } |
343 | | - |
344 | | - /** |
345 | | - * Rejects class names where the supplied ClassNameMatcher matches for deserialization, even if they are otherwise accepted. |
346 | | - * <p> |
347 | | - * The reject list takes precedence over the accept list. |
348 | | - * </p> |
349 | | - * |
350 | | - * @param m the matcher to use |
351 | | - * @return this instance. |
352 | | - */ |
353 | | - public ObjectStreamClassPredicate reject(final ClassNameMatcher m) { |
354 | | - rejectMatchers.add(m); |
355 | | - return this; |
356 | | - } |
357 | | - |
358 | | - /** |
359 | | - * Rejects class names that match the supplied pattern for deserialization, even if they are otherwise accepted. |
360 | | - * <p> |
361 | | - * The reject list takes precedence over the accept list. |
362 | | - * </p> |
363 | | - * |
364 | | - * @param pattern standard Java regexp |
365 | | - * @return this instance. |
366 | | - */ |
367 | | - public ObjectStreamClassPredicate reject(final Pattern pattern) { |
368 | | - rejectMatchers.add(new RegexpClassNameMatcher(pattern)); |
369 | | - return this; |
370 | | - } |
371 | | - |
372 | | - /** |
373 | | - * Rejects the wildcard specified classes for deserialization, even if they are otherwise accepted. |
374 | | - * <p> |
375 | | - * The reject list takes precedence over the accept list. |
376 | | - * </p> |
377 | | - * |
378 | | - * @param patterns Wildcard file name patterns as defined by {@link org.apache.commons.io.FilenameUtils#wildcardMatch(String, String) |
379 | | - * FilenameUtils.wildcardMatch} |
380 | | - * @return this instance. |
381 | | - */ |
382 | | - public ObjectStreamClassPredicate reject(final String... patterns) { |
383 | | - Stream.of(patterns).map(WildcardClassNameMatcher::new).forEach(rejectMatchers::add); |
384 | | - return this; |
385 | | - } |
386 | | - |
387 | | - /** |
388 | | - * Tests that the ObjectStreamClass conforms to requirements. |
389 | | - * <p> |
390 | | - * The reject list takes precedence over the accept list. |
391 | | - * </p> |
392 | | - * |
393 | | - * @param objectStreamClass The ObjectStreamClass to test. |
394 | | - * @return true if the input is accepted, false if rejected, false if neither. |
395 | | - */ |
396 | | - @Override |
397 | | - public boolean test(final ObjectStreamClass objectStreamClass) { |
398 | | - return test(objectStreamClass.getName()); |
399 | | - } |
400 | | - |
401 | | - /** |
402 | | - * Tests that the class name conforms to requirements. |
403 | | - * <p> |
404 | | - * The reject list takes precedence over the accept list. |
405 | | - * </p> |
406 | | - * |
407 | | - * @param name The class name to test. |
408 | | - * @return true if the input is accepted, false if rejected, false if neither. |
409 | | - */ |
410 | | - public boolean test(final String name) { |
411 | | - // The reject list takes precedence over the accept list. |
412 | | - for (final ClassNameMatcher m : rejectMatchers) { |
413 | | - if (m.matches(name)) { |
414 | | - return false; |
415 | | - } |
416 | | - } |
417 | | - for (final ClassNameMatcher m : acceptMatchers) { |
418 | | - if (m.matches(name)) { |
419 | | - return true; |
420 | | - } |
421 | | - } |
422 | | - return false; |
423 | | - } |
424 | | - |
425 | | - } |
426 | | - |
427 | 246 | /** |
428 | 247 | * Constructs a new {@link Builder}. |
429 | 248 | * |
|
0 commit comments