当前位置: 首页>>代码示例>>Java>>正文


Java CsvMapReader.close方法代码示例

本文整理汇总了Java中org.supercsv.io.CsvMapReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java CsvMapReader.close方法的具体用法?Java CsvMapReader.close怎么用?Java CsvMapReader.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.supercsv.io.CsvMapReader的用法示例。


在下文中一共展示了CsvMapReader.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readOneFile

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
@Override
public ImportData readOneFile( File file ) throws IOException, ImportValidationException {
	ImportData data = new ImportData();
	ImportMetadata im = data.getMetadata();
	im.setSourceOfData( new URIImpl( file.toURI().toString() ) );
	im.setLegacyMode( true );

	try ( Reader rdr = new BufferedReader( new FileReader( file ) ) ) {
		mapReader = new CsvMapReader( rdr, CsvPreference.STANDARD_PREFERENCE );
		File propfile = propCSVFile( mapReader );
		setRdfMapFromFile( propfile ); // will throw an IOException if missing file

		createProcessors();
		processConceptRelationURIs( data );
		processNodePropURIs( data );
		processRelationships( data );
	}
	finally {
		if ( null != mapReader ) {
			mapReader.close();
		}
	}

	return data;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:26,代码来源:CSVReader.java

示例2: test3

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
public static void test3(RandomLineAccessFile file) throws Exception{
	CsvMapReader reader = new CsvMapReader(file.getReader(), CsvPreference.STANDARD_PREFERENCE);
	String[] header = reader.getCSVHeader(false);
	for(String s : header) System.out.print(s + "|");
	System.out.println();
	Map<String, String> row;
	while((row = reader.read(header)) != null){
		for(String data : row.values()) System.out.print(data + "|");
		System.out.println();
	}
	reader.close();
}
 
开发者ID:Cride5,项目名称:jablus,代码行数:13,代码来源:RandomLineAccessFile.java

示例3: test4

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
public static void test4(RandomLineAccessFile file) throws Exception{
	CsvMapReader reader = new CsvMapReader(file.getReader(), CsvPreference.STANDARD_PREFERENCE);
	String[] header = reader.getCSVHeader(false);
	for(String s : header) System.out.print(s + "|");
	System.out.println();
	CellProcessor[] processor = new CellProcessor[]{new Optional(), new ParseDouble(), new ParseLong(), new Optional(), new Optional(), new Optional()};
	Map<String, ? super Object> row = reader.read(header, processor);
	while(row != null && row.size() != 0){
		for(Object data : row.values()) System.out.print(data + "|");
		row = reader.read(header, processor);
		System.out.println();
	}
	reader.close();
}
 
开发者ID:Cride5,项目名称:jablus,代码行数:15,代码来源:RandomLineAccessFile.java

示例4: loadFeatureMetaMap

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
/**
 * Load "feature-metadata" CSV
 * @throws IOException
 */
private void loadFeatureMetaMap() throws IOException {
    String uri = "/feature-metadata-2013.csv";
    try (Reader featIO = new InputStreamReader(GeonamesUtility.class.getResourceAsStream(uri))) {
        CsvMapReader featreader = new CsvMapReader(featIO, CsvPreference.EXCEL_PREFERENCE);
        String[] columns = featreader.getHeader(true);
        Map<String, String> featMap = null;

        // Feature Metadata is from Universal Gazetteer
        // -----------------------------------
        // Feature Designation Code, CODE
        // Feature Designation Name, DESC
        // Feature Designation Text, -
        // Feature Class CLASS
        //
        while ((featMap = featreader.read(columns)) != null) {
            String feat_code = featMap.get("Feature Designation Code");
            String desc = featMap.get("Feature Designation Name");
            String feat_class = featMap.get("Feature Class");

            if (feat_code == null) {
                continue;
            }

            if (feat_code.startsWith("#")) {
                continue;
            }
            features.put(String.format("%s/%s", feat_class, feat_code), desc);
        }
        featreader.close();
    }
}
 
开发者ID:OpenSextant,项目名称:Xponents,代码行数:36,代码来源:GeonamesUtility.java

示例5: loadUSStateMetadata

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
/**
 * <pre> TODO: This is mildly informed by geonames.org, however even there
 * we are still missing a mapping between ADM1 FIPS/ISO codes for a state
 * and the Postal codes/abbreviations.
 * 
 * Aliases for the same US province: "US.25" = "MA" = "US.MA" =
 * "Massachussetts" = "the Bay State"
 * 
 * Easily mapping the coded data (e.g., 'MA' = '25') worldwide would be
 * helpful.
 * 
 * TODO: Make use of geonames.org or other sources for ADM1 postal code
 * listings at top level. </pre>
 * 
 * @throws IOException if CSV file not found in classpath
 */
public void loadUSStateMetadata() throws IOException {
    String uri = "/us-state-metadata.csv";
    try (Reader fio = new InputStreamReader(GeonamesUtility.class.getResourceAsStream(uri))) {
        CsvMapReader adm1CSV = new CsvMapReader(fio, CsvPreference.EXCEL_PREFERENCE);
        String[] columns = adm1CSV.getHeader(true);
        Map<String, String> stateRow = null;

        // -----------------------------------
        // "POSTAL_CODE","ADM1_CODE","STATE","LAT","LON","FIPS_CC","ISO2_CC"
        //
        while ((stateRow = adm1CSV.read(columns)) != null) {

            String roughID = String.format("%s.%s", stateRow.get("ISO2_CC"), stateRow.get("POSTAL_CODE"));
            Place s = new Place(roughID, stateRow.get("STATE"));
            s.setFeatureClass("A");
            s.setFeatureCode("ADM1");
            s.setAdmin1(stateRow.get("ADM1_CODE").substring(2));
            s.setCountryCode(stateRow.get("ISO2_CC"));
            s.defaultHierarchicalPath();
            LatLon yx = GeodeticUtility.parseLatLon(stateRow.get("LAT"), stateRow.get("LON"));
            s.setLatLon(yx);

            s.setAdmin1PostalCode(stateRow.get("POSTAL_CODE"));
            usStateMetadata.add(s);
        }
        adm1CSV.close();
    } catch (Exception err) {
        throw new IOException("Could not load US State data" + uri, err);
    }
}
 
开发者ID:OpenSextant,项目名称:Xponents,代码行数:47,代码来源:GeonamesUtility.java

示例6: loadExclusions

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
/**
 * Exclusions have two columns in a CSV file. 'exclusion', 'category'
 *
 * "#" in exclusion column implies a comment. Call is responsible for
 * getting I/O stream.
 * 
 * @param filestream URL/file with exclusion terms
 * @return set of filter terms
 * @throws ConfigException if filter is not found
 */
public static Set<String> loadExclusions(InputStream filestream) throws ConfigException {
    /*
     * Load the exclusion names -- these are terms that are gazeteer
     * entries, e.g., gazetteer.name = <exclusion term>, that will be marked
     * as search_only = true.
     */
    try (Reader termsIO = new InputStreamReader(filestream)) {
        CsvMapReader termreader = new CsvMapReader(termsIO, CsvPreference.EXCEL_PREFERENCE);
        String[] columns = termreader.getHeader(true);
        Map<String, String> terms = null;
        HashSet<String> stopTerms = new HashSet<String>();
        while ((terms = termreader.read(columns)) != null) {
            String term = terms.get("exclusion");
            if (StringUtils.isBlank(term) || term.startsWith("#")) {
                continue;
            }
            String trimmed = term.trim();
            /* Allow for case-sensitive filtration, if stop terms are listed in native case in resource files */
            stopTerms.add(trimmed);
            stopTerms.add(trimmed.toLowerCase());
        }
        termreader.close();
        return stopTerms;
    } catch (Exception err) {
        throw new ConfigException("Could not load exclusions.", err);
    }
}
 
开发者ID:OpenSextant,项目名称:Xponents,代码行数:38,代码来源:TagFilter.java

示例7: getData

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
public HierarchicalConfiguration getData(final String className,
        HierarchicalConfiguration context) {
    HierarchicalConfiguration testData = null;
    try {
        Class<?> clazz = Class.forName(className);
        String dataFilePath = null;
        URL dataFileURL = null;
        String dataFileName = context.getString("supplier.dataFile", null);
        log.debug("Checking the data file in argument...");
        if (dataFileName == null || dataFileName.equals("")) {
            log.debug("Data file not given in argument..Using DataFileFinder..");
            dataFilePath = DDUtils.findDataFile(className, ".csv", context);
        } else {
            log.debug("Got data file in argument");
            dataFilePath = dataFileName;
        }
        log.debug("Data file path: " + dataFilePath);
        if (dataFilePath == null) {
            return null;// No data found, hence it's a normal test case.
        }
        dataFileURL = clazz.getResource(dataFilePath);
        CsvMapReader reader = new CsvMapReader(new InputStreamReader(dataFileURL.openStream()),
                CsvPreference.STANDARD_PREFERENCE);
        String list[] = reader.getHeader(true);
        Map<String, String> map = null;
        testData = new HierarchicalConfiguration();
        int i = 0;
        while ((map = reader.read(list)) != null) {
            String testId = null;
            HierarchicalConfiguration newData = new HierarchicalConfiguration();
            Set<Map.Entry<String, String>> entrySet = map.entrySet();
            for (Map.Entry<String, String> entry : entrySet) {
                if (entry.getKey().equals("test-id")) {
                    newData.addProperty("[@test-id]", entry.getValue());
                    testId = entry.getValue();
                    continue;
                }
                newData.addProperty(entry.getKey(), entry.getValue());
            }
            testData.addNodes("data(" + i + ")", newData.getRootNode().getChildren());
            if (testId != null) {
                testData.addProperty("data(" + i + ")[@test-id]", testId);
            }
            i++;
        }
        reader.close();
    } catch (Exception ex) {
        throw new DDException("Error in loading data file", ex);
    }
    return testData;
}
 
开发者ID:vmware,项目名称:data-driven-framework,代码行数:52,代码来源:CSVDataSupplier.java

示例8: main

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    File input = new File(args[0]);
    System.out.println("Reading from: " + input.getAbsolutePath());

    CsvPreference preferences = CsvPreference.STANDARD_PREFERENCE;
    CsvMapReader cmr = new CsvMapReader(new FileReader(input), preferences);
    Map<String, String> read = cmr.read(new String[] { TIME, SOURCE, DATA });
    System.out.println("\"time\",\"M\",\"MHR\",\"FHR\",\"TOCO\",\"QFHR\"");
    boolean mark = false;
    while (read != null) {
        Date time = new Date(Long.parseLong(read.get(TIME)));
        byte[] bytes = hex2bytes(read.get(DATA));
        String data = bytes2string(bytes);

        if (data.length() != bytes.length) {
            System.out.println("Length error: String:" + data.length() + " bytes:" + bytes.length);
            return;
        } else {
            for (int i = 0; i < bytes.length; i++) {
                if (bytes[i] != (byte) data.charAt(i)) {
                    System.out.println("*****************************          byte: " + bytes[i] + " char: "
                            + data.charAt(i));
                    return;
                }
            }
        }

        if (data.equals("MM")) {
            mark = true;
        } else if (data.startsWith("C")) {
            CBlockMessage cb = new CBlockMessage(time, data);
            float[] mhr = cb.getMHR();
            float[] fhr = cb.getFHR1();
            float[] toco = cb.getTOCO();
            int[] qfhr = cb.getQFHR1();

            for (int i = 0; i < mhr.length; i++) {
                System.out.print((time.getTime() + 500) / 1000 + ",");
                if (mark) {
                    System.out.print("10,");
                } else {
                    System.out.print("0,");
                }
                System.out.print(mhr[i] + ",");
                System.out.print(fhr[i] + ",");
                System.out.print(toco[i] + ",");
                System.out.print(qfhr[i] + "");
                System.out.println();
                mark = false;
            }
        } else if (data.startsWith("N02ANS")) {

            // System.out.print((time.getTime() + 500) / 1000 + ",");
            // int start = "N02ANS".length();
            // int fh = Integer.parseInt(data.substring(start, start + 4), 16);
            // int n = Integer.parseInt(data.substring(start + 4, start + 8), 16);
            // System.out.println(fh + "," + n);
        } else {
            // StringBuffer sb = new StringBuffer();
            // for (int i = 0; i < data.length(); i++) {
            // char ch = data.charAt(i);
            // if (ch > ' ' && ch < 127)
            // sb.append(ch);
            // else
            // break;
            // }
            // System.out.println(sb + " [" + data.length() + "]");
        }

        read = cmr.read(new String[] { TIME, SOURCE, DATA });
    }

    cmr.close();
}
 
开发者ID:silverbullet-dk,项目名称:opentele-client-android,代码行数:79,代码来源:ReadCtgDataLog.java

示例9: readTable

import org.supercsv.io.CsvMapReader; //导入方法依赖的package包/类
static
public Table<EvaluationRequest> readTable(BufferedReader reader, CsvPreference format) throws IOException {
	Table<EvaluationRequest> table = new Table<>();

	CsvMapReader parser = new CsvMapReader(reader, format);

	String[] header = parser.getHeader(true);

	if(header.length > 0 && ("id").equalsIgnoreCase(header[0])){
		table.setId(header[0]);
	}

	List<EvaluationRequest> requests = new ArrayList<>();

	while(true){
		Map<String, String> arguments = parser.read(header);
		if(arguments == null){
			break;
		}

		String id = arguments.remove(table.getId());

		EvaluationRequest request = new EvaluationRequest(id);
		request.setArguments(arguments);

		requests.add(request);
	}

	parser.close();

	table.setRows(requests);

	return table;
}
 
开发者ID:openscoring,项目名称:openscoring,代码行数:35,代码来源:CsvUtil.java


注:本文中的org.supercsv.io.CsvMapReader.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。