All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.lightningcsv.parser.StringArrayCellConsumerNoCopyFixedLength Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.lightningcsv.parser;

import org.simpleflatmapper.util.CheckedConsumer;
import org.simpleflatmapper.util.ErrorHelper;

public final class StringArrayCellConsumerNoCopyFixedLength> implements CellConsumer {
        private final RH handler;
        private int currentIndex;
        private String[] currentRow;

        public StringArrayCellConsumerNoCopyFixedLength(RH handler, int numberOfCells) {
            this.handler = handler;
            this.currentRow = new String[numberOfCells];
        }

        public void newCell(char[] chars, int offset, int length) {
            int currentIndex = this.currentIndex;
            String[] currentRow = this.currentRow;
            if (currentIndex < currentRow.length) {
                currentRow[currentIndex] = length > 0 ? new String(chars, offset, length) : "";
                this.currentIndex++;
            }
        }


        public boolean endOfRow() {
            try {
                return this._endOfRow();
            } catch (Exception var2) {
                return (Boolean) ErrorHelper.rethrow(var2);
            }
        }

        private boolean _endOfRow() throws Exception {
            this.handler.accept(currentRow);
            this.currentIndex = 0;
            return true;
        }

        public RH handler() {
            return this.handler;
        }

        public void end() {
            if (this.currentIndex > 0) {
                this.endOfRow();
            }

        }
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy