Skip to content

Commit 813dfa1

Browse files
Fix cmp file
1 parent 978504e commit 813dfa1

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

kernel/src/main/java/com/itextpdf/kernel/utils/CompareTool.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ private boolean compareStreamsExtended(PdfStream outStream, PdfStream cmpStream,
786786
if (cmpStreamBytes.length != outStreamBytes.length) {
787787
errorMessage += String.format("PdfStream. Lengths are different. Expected: %s. Found: %s", cmpStreamBytes.length, outStreamBytes.length) + "\n";
788788
} else {
789-
errorMessage += "PdfStream. Lengths are the same. But bytes are different:\n";
789+
errorMessage += "PdfStream. Bytes are different.\n";
790790
}
791791
String bytesDifference = findBytesDifference(outStreamBytes, cmpStreamBytes);
792792
if (bytesDifference != null) {
@@ -805,7 +805,8 @@ private boolean compareStreamsExtended(PdfStream outStream, PdfStream cmpStream,
805805
private String findBytesDifference(byte[] outStreamBytes, byte[] cmpStreamBytes) {
806806
int numberOfDifferentBytes = 0;
807807
int firstDifferenceOffset = 0;
808-
for (int i = 0; i < Math.min(cmpStreamBytes.length, outStreamBytes.length); i++) {
808+
int minLength = Math.min(cmpStreamBytes.length, outStreamBytes.length);
809+
for (int i = 0; i < minLength; i++) {
809810
if (cmpStreamBytes[i] != outStreamBytes[i]) {
810811
++numberOfDifferentBytes;
811812
if (numberOfDifferentBytes == 1) {
@@ -826,7 +827,7 @@ private String findBytesDifference(byte[] outStreamBytes, byte[] cmpStreamBytes)
826827
errorMessage = String.format("First bytes difference is encountered at index %s. Expected: %s (%s). Found: %s (%s). Total number of different bytes: %s",
827828
firstDifferenceOffset, cmpByte, cmpByteNeighbours, outByte, outBytesNeighbours, numberOfDifferentBytes);
828829
} else { // lengths are different
829-
errorMessage = "Lengths are different, but bytes of the shorter array are the same as the first bytes of the longer one.";
830+
errorMessage = String.format("Bytes of the shorter array are the same as the first %s bytes of the longer one.", minLength);
830831
}
831832

832833
return errorMessage;

kernel/src/test/resources/com/itextpdf/kernel/utils/CompareToolTest/cmp_report01.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<report>
33
<errors count="4">
44
<error>
5-
<message>PdfStream. The bytes differ at index 1715. Expected: 3 ( 502 196.13 16 reS). Found: 5 ( 502 196.15 16 reS)</message>
5+
<message>PdfStream. Bytes are different.
6+
First bytes difference is encountered at index 1715. Expected: 3 ( 502 196.13 16 re S ). Found: 5 ( 502 196.15 16 re S ). Total number of different bytes: 1</message>
67
<path>
78
<base cmp="3 0 obj" out="3 0 obj"/>
8-
<offset>1715</offset>
99
</path>
1010
</error>
1111
<error>

0 commit comments

Comments
 (0)