This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 11e8800e5d14921e93f1600d5d2a5c9457c0f77d Author: Gary Gregory <[email protected]> AuthorDate: Tue Jul 1 17:15:09 2025 -0400 Internal refactoring No need to separately track "first bytes" length in an instance variable --- .../org/apache/commons/io/input/BOMInputStream.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/io/input/BOMInputStream.java b/src/main/java/org/apache/commons/io/input/BOMInputStream.java index 2caf29760..e7b6c3c47 100644 --- a/src/main/java/org/apache/commons/io/input/BOMInputStream.java +++ b/src/main/java/org/apache/commons/io/input/BOMInputStream.java @@ -229,7 +229,6 @@ public static Builder builder() { private ByteOrderMark byteOrderMark; private int fbIndex; - private int fbLength; private int[] firstBytes; private final boolean include; private boolean markedAtStart; @@ -458,26 +457,27 @@ public int read(final byte[] buf, int off, int len) throws IOException { } private ByteOrderMark readBom() throws IOException { - fbLength = 0; + int fbLength = 0; // BOMs are sorted from longest to shortest final int maxBomSize = bomList.get(0).length(); - firstBytes = new int[maxBomSize]; + final int[] tmp = new int[maxBomSize]; // Read first maxBomSize bytes - for (int i = 0; i < firstBytes.length; i++) { - firstBytes[i] = in.read(); - afterRead(firstBytes[i]); + for (int i = 0; i < tmp.length; i++) { + tmp[i] = in.read(); + afterRead(tmp[i]); fbLength++; - if (firstBytes[i] < 0) { + if (tmp[i] < 0) { break; } } + firstBytes = Arrays.copyOf(tmp, fbLength); // match BOM in firstBytes final ByteOrderMark bom = find(); if (bom != null && !include) { if (bom.length() < firstBytes.length) { fbIndex = bom.length(); } else { - fbLength = 0; + firstBytes = new int[0]; } } return bom; @@ -494,7 +494,7 @@ private ByteOrderMark readBom() throws IOException { */ private int readFirstBytes() throws IOException { getBOM(); - return fbIndex < fbLength ? firstBytes[fbIndex++] : EOF; + return fbIndex < firstBytes.length ? firstBytes[fbIndex++] : EOF; } /**
