Skip to content

Commit 11e8800

Browse files
committed
Internal refactoring
No need to separately track "first bytes" length in an instance variable
1 parent 99aad6d commit 11e8800

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/main/java/org/apache/commons/io/input/BOMInputStream.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ public static Builder builder() {
229229

230230
private ByteOrderMark byteOrderMark;
231231
private int fbIndex;
232-
private int fbLength;
233232
private int[] firstBytes;
234233
private final boolean include;
235234
private boolean markedAtStart;
@@ -458,26 +457,27 @@ public int read(final byte[] buf, int off, int len) throws IOException {
458457
}
459458

460459
private ByteOrderMark readBom() throws IOException {
461-
fbLength = 0;
460+
int fbLength = 0;
462461
// BOMs are sorted from longest to shortest
463462
final int maxBomSize = bomList.get(0).length();
464-
firstBytes = new int[maxBomSize];
463+
final int[] tmp = new int[maxBomSize];
465464
// Read first maxBomSize bytes
466-
for (int i = 0; i < firstBytes.length; i++) {
467-
firstBytes[i] = in.read();
468-
afterRead(firstBytes[i]);
465+
for (int i = 0; i < tmp.length; i++) {
466+
tmp[i] = in.read();
467+
afterRead(tmp[i]);
469468
fbLength++;
470-
if (firstBytes[i] < 0) {
469+
if (tmp[i] < 0) {
471470
break;
472471
}
473472
}
473+
firstBytes = Arrays.copyOf(tmp, fbLength);
474474
// match BOM in firstBytes
475475
final ByteOrderMark bom = find();
476476
if (bom != null && !include) {
477477
if (bom.length() < firstBytes.length) {
478478
fbIndex = bom.length();
479479
} else {
480-
fbLength = 0;
480+
firstBytes = new int[0];
481481
}
482482
}
483483
return bom;
@@ -494,7 +494,7 @@ private ByteOrderMark readBom() throws IOException {
494494
*/
495495
private int readFirstBytes() throws IOException {
496496
getBOM();
497-
return fbIndex < fbLength ? firstBytes[fbIndex++] : EOF;
497+
return fbIndex < firstBytes.length ? firstBytes[fbIndex++] : EOF;
498498
}
499499

500500
/**

0 commit comments

Comments
 (0)