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

io.ciera.tool.sql.ooaofmarking.impl.CSVImpl Maven / Gradle / Ivy

There is a newer version: 2.7.3
Show newest version
package io.ciera.tool.sql.ooaofmarking.impl;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import io.ciera.runtime.summit.components.IComponent;
import io.ciera.runtime.summit.util.Utility;
import io.ciera.tool.sql.ooaofmarking.CSV;

public class CSVImpl> extends Utility implements CSV {

    private Scanner sc;
    private String inputFilename;

    public CSVImpl(C context) {
        super(context);
        sc = null;
        inputFilename = "";
    }

    public int readline(final String p_filename, final String[] p_values) {
        // set up input
        if (null == sc || !inputFilename.equals(p_filename)) {
            inputFilename = p_filename;
            if (null != sc)
                sc.close();
            File file = new File(inputFilename);
            try {
                sc = new Scanner(file);
            } catch (FileNotFoundException e) {
                getRunContext().getLog().error(e);
                return 0;
            }
        }
        // get next line of input
        String line = "";
        while (sc.hasNextLine() && "".equals(line)) {
            line = sc.nextLine();
            if (line.trim().startsWith("#")) { // skip comment lines
                line = "";
                continue;
            }
        }
        // split line into values
        if (!"".equals(line)) {
            String[] values = line.split(",");
            for (int i = 0; i < values.length; i++) {
                p_values[i] = values[i].trim();
            }
            return values.length;
        } else
            return 0;
    }

    public int writeline(final String p_filename, final String[] p_values) {
        return 0;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy