import java.util.Arrays;
import java.util.List;
+import org.apache.poi.util.IOUtils;
import org.apache.poi.util.RecordFormatException;
/**
public final class RecordFactory {
private static final int NUM_RECORDS = 512;
+ // how many records we read at max by default (can be adjusted via IOUtils)
+ private static final int MAX_NUMBER_OF_RECORDS = 1_000_000;
+
private RecordFactory() {}
/**
* @return the equivalent array of {@link NumberRecord NumberRecords}
*/
public static NumberRecord[] convertRKRecords(MulRKRecord mrk) {
- if (mrk.getNumColumns() < 0) {
- throw new RecordFormatException("Cannot create RKRecords with negative number of columns: " + mrk.getNumColumns());
+ int numColumns = mrk.getNumColumns();
+ if (numColumns < 0) {
+ throw new RecordFormatException("Cannot create RKRecords with negative number of columns: " + numColumns);
}
- NumberRecord[] mulRecs = new NumberRecord[mrk.getNumColumns()];
- for (int k = 0; k < mrk.getNumColumns(); k++) {
+ NumberRecord[] mulRecs = new NumberRecord[numColumns];
+ for (int k = 0; k < numColumns; k++) {
NumberRecord nr = new NumberRecord();
nr.setColumn((short) (k + mrk.getFirstColumn()));
Record record;
while ((record = recStream.nextRecord())!=null) {
records.add(record);
+
+ IOUtils.safelyAllocateCheck(records.size(), MAX_NUMBER_OF_RECORDS);
}
return records;