Internal refactoring
No need to separately track "first bytes" length in an instance variable
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 2caf297..e7b6c3c 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;
}
/**