+ // Look for whitespace after pattern:
+ int lastPatternSize = 0;
+ for (int i = 0; i < counters.length; i++) {
+ lastPatternSize += counters[i];
+ }
+ int whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize;
+ // If 50% of last pattern size, following last pattern, is not whitespace, fail
+ // (but if it's whitespace to the very end of the image, that's OK)
+ if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) {
+ throw new ReaderException("Pattern not followed by whitespace");
+ }
+