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

coffeepot.bean.wr.reader.DelimitedReader Maven / Gradle / Ivy

Go to download

Coffeepot-bean-wr is a simple Java framework for marshalling Java beans to flat file and unmarshal flat file to Java Beans

There is a newer version: 2.0.0-rc.5
Show newest version
/*
 * Copyright 2015 Jeandeson O. Merelis.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package coffeepot.bean.wr.reader;

/*
 * #%L
 * coffeepot-bean-wr
 * %%
 * Copyright (C) 2013 - 2015 Jeandeson O. Merelis
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
import coffeepot.bean.wr.mapper.ObjectMapperFactory;
import coffeepot.bean.wr.types.FormatType;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.regex.Pattern;

/**
 *
 * @author Jeandeson O. Merelis
 */
public class DelimitedReader extends AbstractReader {

    protected final static int ID_POSITION = 0;
    protected char delimiter = ';';
    private Character escape;
    private String regexSplit;
    private String escOld;
    private String escNew;
    private String delimOld;
    private String delimNew;

    protected String[] currentRecord;
    protected String[] nextRecord;

    private final ObjectMapperFactory mapperFactory = new ObjectMapperFactory(FormatType.DELIMITED);

    public DelimitedReader(Reader reader) {
        super(reader);
    }

    @Override
    public ObjectMapperFactory getObjectMapperFactory() {
        return mapperFactory;
    }

    public char getDelimiter() {
        return delimiter;
    }

    public void setDelimiter(char delimiter) {
        this.delimiter = delimiter;
    }

    public Character getEscape() {
        return escape;
    }

    public void setEscape(Character escape) {
        this.escape = escape;
    }

    @Override
    protected void clear() {
        super.clear();
        currentRecord = null;
    }

    @Override
    protected void config() {
        String delim = "" + delimiter;
        if (escape != null) {
            String esc = String.valueOf(escape);
            regexSplit = "(?




© 2015 - 2024 Weber Informatics LLC | Privacy Policy