@@ -402,9 +402,9 @@ else if (value instanceof COSInteger && !((COSInteger) value).isValid())
402
402
}
403
403
404
404
/**
405
- * Skip the upcoming CRLF or LF which are supposed to follow a stream.
405
+ * Skip the upcoming CRLF or LF which are supposed to follow a stream. Trailing spaces are removed as well.
406
406
*
407
- * @throws IOException
407
+ * @throws IOException if something went wrong
408
408
*/
409
409
protected void skipWhiteSpaces () throws IOException
410
410
{
@@ -418,24 +418,55 @@ protected void skipWhiteSpaces() throws IOException
418
418
{
419
419
whitespace = source .read ();
420
420
}
421
+ if (!skipLinebreak (whitespace ))
422
+ {
423
+ source .rewind (1 );
424
+ }
425
+ }
421
426
422
- if (isCR (whitespace ))
427
+ /**
428
+ * Skip one line break, such as CR, LF or CRLF.
429
+ *
430
+ * @return true if a line break was found and removed.
431
+ *
432
+ * @throws IOException if something went wrong
433
+ */
434
+ protected boolean skipLinebreak () throws IOException
435
+ {
436
+ // a line break is a CR, or LF or CRLF
437
+ if (!skipLinebreak (source .read ()))
423
438
{
424
- whitespace = source .read ();
425
- if (!isLF (whitespace ))
439
+ source .rewind (1 );
440
+ return false ;
441
+ }
442
+ return true ;
443
+ }
444
+
445
+ /**
446
+ * Skip one line break, such as CR, LF or CRLF.
447
+ *
448
+ * @param linebreak the first character to be checked.
449
+ *
450
+ * @return true if a line break was found and removed.
451
+ *
452
+ * @throws IOException if something went wrong
453
+ */
454
+ private boolean skipLinebreak (int linebreak ) throws IOException
455
+ {
456
+ // a line break is a CR, or LF or CRLF
457
+ if (isCR (linebreak ))
458
+ {
459
+ int next = source .read ();
460
+ if (!isLF (next ))
426
461
{
427
462
source .rewind (1 );
428
- //The spec says this is invalid but it happens in the real
429
- //world so we must support it.
430
463
}
431
464
}
432
- else if (!isLF (whitespace ))
465
+ else if (!isLF (linebreak ))
433
466
{
434
- //we are in an error.
435
- //but again we will do a lenient parsing and just assume that everything
436
- //is fine
437
- source .rewind (1 );
467
+ return false ;
438
468
}
469
+ return true ;
439
470
}
440
471
441
472
/**
0 commit comments