|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -508,30 +508,31 @@ public void updateMessageDigest(MessageDigest messageDigest, int len) {
|
508 | 508 | // This stream doesn't have any data in it...
|
509 | 509 | return;
|
510 | 510 | }
|
511 |
| - else if (len == 0) { |
| 511 | + |
| 512 | + if (len == 0) { |
512 | 513 | return;
|
513 | 514 | }
|
514 |
| - else if (len < 0) { |
| 515 | + |
| 516 | + if (len < 0) { |
515 | 517 | throw new IllegalArgumentException("len must be 0 or greater: " + len);
|
516 | 518 | }
|
| 519 | + |
| 520 | + if (this.nextIndexInCurrentBuffer < this.currentBufferLength) { |
| 521 | + int bytesToCopy = Math.min(len, this.currentBufferLength - this.nextIndexInCurrentBuffer); |
| 522 | + messageDigest.update(this.currentBuffer, this.nextIndexInCurrentBuffer, bytesToCopy); |
| 523 | + this.nextIndexInCurrentBuffer += bytesToCopy; |
| 524 | + updateMessageDigest(messageDigest, len - bytesToCopy); |
| 525 | + } |
517 | 526 | else {
|
518 |
| - if (this.nextIndexInCurrentBuffer < this.currentBufferLength) { |
519 |
| - int bytesToCopy = Math.min(len, this.currentBufferLength - this.nextIndexInCurrentBuffer); |
520 |
| - messageDigest.update(this.currentBuffer, this.nextIndexInCurrentBuffer, bytesToCopy); |
521 |
| - this.nextIndexInCurrentBuffer += bytesToCopy; |
522 |
| - updateMessageDigest(messageDigest, len - bytesToCopy); |
| 527 | + if (this.buffersIterator.hasNext()) { |
| 528 | + this.currentBuffer = this.buffersIterator.next(); |
| 529 | + updateCurrentBufferLength(); |
| 530 | + this.nextIndexInCurrentBuffer = 0; |
523 | 531 | }
|
524 | 532 | else {
|
525 |
| - if (this.buffersIterator.hasNext()) { |
526 |
| - this.currentBuffer = this.buffersIterator.next(); |
527 |
| - updateCurrentBufferLength(); |
528 |
| - this.nextIndexInCurrentBuffer = 0; |
529 |
| - } |
530 |
| - else { |
531 |
| - this.currentBuffer = null; |
532 |
| - } |
533 |
| - updateMessageDigest(messageDigest, len); |
| 533 | + this.currentBuffer = null; |
534 | 534 | }
|
| 535 | + updateMessageDigest(messageDigest, len); |
535 | 536 | }
|
536 | 537 | }
|
537 | 538 |
|
|
0 commit comments