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


Java CSVParser.parse方法代码示例

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


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

示例1: parseHintFile

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
private HashMap<String, Map<String, String>> parseHintFile(Integer exercise, Integer exercise_order)  {

		final HashMap<String, Map<String, String>> list;
		final CSVParser parser;
		final URL resource;
		final CSVFormat csvFormat;
		final Charset charset;
		list = new HashMap<String, Map<String, String>>  ();
		try {
			resource = ResourceHelper.getResource(BuenOjoFileUtils.GAME_RESOURCES_INPUT_DIR ,this.gamePath,this.setPath,exercise.toString(),exercise_order.toString(),"xy_pista.csv");
			charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
			csvFormat = CSVFormatHelper.getDefaultCSVFormat();
			parser = CSVParser.parse(resource, charset, csvFormat);
			for (CSVRecord record : parser )
				list.put(record.get("id").trim() , (Map<String, String>)record.toMap());
		}
		catch (IOException e) {
			log.error("Fail",e);
		}
		return list;
		
	}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:23,代码来源:HangManExerciseHintLoader.java

示例2: parse

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
private ArrayList<Map<String, String>> parse()  {
	final ArrayList<Map<String, String>> list;
	final CSVParser parser;
	final URL resource;
	final CSVFormat csvFormat;
	final Charset charset;
	list = new ArrayList<Map<String, String>> ();
	try {
		resource = ResourceHelper.getResource(isFromGameResourceInput(),fileName);
		charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
		csvFormat = CSVFormatHelper.getDefaultCSVFormat();
		parser = CSVParser.parse(resource, charset, csvFormat);
		for (CSVRecord record : parser )
			list.add((Map<String, String>)record.toMap());
	}
	catch (IOException e) {
		log.error("Fail", e);
	}
	return list;
	
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:22,代码来源:HangManExerciseHintLoader.java

示例3: parse

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
private ArrayList<Map<String,String>> parse()  {

		ArrayList<Map<String,String>> list;
		CSVParser parser;
		URL resource;
		CSVFormat csvFormat;
		Charset charset;
		list = new ArrayList<Map<String,String>> ();
		try {
			resource = ResourceHelper.getResource(isFromGameResourceInput(),fileName);
			charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
			csvFormat = CSVFormatHelper.getDefaultCSVFormat();
			parser = CSVParser.parse(resource, charset, csvFormat);
			for (CSVRecord record : parser )
				list.add(record.toMap());
		}
		catch (IOException e) {
			log.error("Fail", e);
		}
		return list;
		
	}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:23,代码来源:HangManExerciseDelimitedAreaLoader.java

示例4: parseDelimitedAreaFile

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
private  Map<String,String> parseDelimitedAreaFile(Integer exercise, Integer exercise_order)  {

		Map<String,String> list;
		CSVParser parser;
		URL resource;
		CSVFormat csvFormat;
		Charset charset;
		list = new HashMap<String,String>();
		try {
			
			resource =ResourceHelper.getResource(isFromGameResourceInput(),this.gamePath,this.setPath,exercise.toString(), exercise_order.toString(),"areaDelimitada.csv");
			charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
								
			csvFormat = CSVFormatHelper.getDefaultCSVFormat();
			parser = CSVParser.parse(resource, charset, csvFormat);
			for (CSVRecord record : parser )
				list = record.toMap();
		}
		catch (IOException e) {
			log.error("Fail",e);
		}
		return list;
		
	}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:25,代码来源:HangManExerciseDelimitedAreaLoader.java

示例5: importSheet

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
/**
 * Imports a Sheet from a CSV file in the specified path.
 * @param path a CSV File Path.
 * @return a new Sheet or null if parsing failed
 */
public Sheet importSheet(String path) {
    File csvData = new File(path);

    // Parse the CSV file.
    CSVParser parser;

    try {
        parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180);
    } catch (IOException e) {
        return null;
    }

    // Create our new sheet.
    Sheet sheet = new Sheet("Imported Sheet");

    // Populate its cells.
    for (CSVRecord record : parser) {
        for (int x = 0; x < record.size(); ++x) {
            sheet.setCellValue(x, (int) record.getRecordNumber() - 1, record.get(x), true);
        }
    }

    return sheet;
}
 
开发者ID:OrfeasZ,项目名称:AweSheet,代码行数:30,代码来源:CSVManager.java

示例6: main

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
	CSVParser parser = CSVParser.parse(new File("dev/twitter-hate-speech-processed.csv"), Charset.forName("Cp1252"), CSVFormat.DEFAULT);
	try (PrintWriter writer = new PrintWriter("training/bad/model_comments_bad_tweets.txt", "UTF-8")) {
		boolean skipFirst = true;
		for (CSVRecord r : parser) {
			if (skipFirst){
				skipFirst=false;
				continue;
			}
			String classif = r.get(0);
			if (classif.equalsIgnoreCase("The tweet is not offensive")) {
				continue;
			}
			writer.println(r.get(2));
			
		}
	}finally {
		parser.close();
	}
}
 
开发者ID:SOBotics,项目名称:SOCVFinder,代码行数:21,代码来源:TweetsToCommentFormat.java

示例7: invoke

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public String invoke(String sender, String messageContent) {
    try {
        String command = messageContent;
        List<String> commandArgs = new ArrayList<>();
        if (messageContent.contains(" ")) {
            command = substringBefore(messageContent, " ");
            String args = substringAfter(messageContent, " ");

            CSVParser csvRecords = CSVParser.parse(args, CSVFormat.newFormat(' ').withQuote('"'));
            commandArgs = Lists.newArrayList(csvRecords.iterator().next().iterator());

            commandArgs = commandArgs.stream()
                    .map((arg) -> arg.startsWith("$") ? store.get(sender, substringAfter(arg, "$"), String.class) : arg)
                    .collect(Collectors.toList());
        }
        return commands.get(command).invoke(sender, commandArgs);
    } catch (Exception ex) {
        throw new JanuszException(ex);
    }
}
 
开发者ID:TouK,项目名称:janusz,代码行数:21,代码来源:CommandInvoker.java

示例8: getResponse

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
/**
 * Retrieves the answers of responseID for the survey identified by surveyID
 * 
 * @param surveyID
 *            identifier of the survey
 * @param responseID
 *            identifier of the response
 * @return the answers of responseID for the survey identified by surveyID
 * @throws ClientProtocolException
 * @throws IOException
 */
public Hashtable<String, String> getResponse(int surveyID, int responseID)
		throws ClientProtocolException, IOException {
	String sessionKey = getSessionKey();
	String responses = exportResponseByResponseID(sessionKey, surveyID,
			responseID);

	CSVParser csvParser = CSVParser.parse(responses, CSVFormat.RFC4180);
	List<CSVRecord> csvRecordsList = csvParser.getRecords();
	CSVRecord csvQuestions = csvRecordsList.get(0);
	CSVRecord csvAnswers = csvRecordsList.get(1);

	Iterator<String> iterQuestion = csvQuestions.iterator();
	Iterator<String> iterAnswer = csvAnswers.iterator();

	Hashtable<String, String> questionAnswerDictionary = new Hashtable<String, String>();
	while (iterQuestion.hasNext()) {
		String question = iterQuestion.next();
		String answer = iterAnswer.next();
		if (!isIgnoredKey(question))
			questionAnswerDictionary.put(formatQuestion(question),
					formatAnswer(answer));

	}
	return questionAnswerDictionary;
}
 
开发者ID:RISCOSS,项目名称:riscoss-data-collector,代码行数:37,代码来源:LimeSurveyClient.java

示例9: map

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
@Override
public void map(Text key, BytesWritable value, Context context)
		throws IOException, InterruptedException {
	ByteArrayInputStream inputStream = new ByteArrayInputStream(
			value.getBytes());
	int n = value.getLength();
	byte[] bytes = new byte[n];
	inputStream.read(bytes, 0, n);
	CSVParser parser = CSVParser
			.parse(new String(bytes), CSVFormat.DEFAULT);
	try {
		for (CSVRecord csvRecord : parser) {
			for (String string : csvRecord) {
				word.set(string);
				context.write(word, one);
				Counter counter = context.getCounter(
						CountersEnum.class.getName(),
						CountersEnum.INPUT_WORDS.toString());
				counter.increment(1);
			}
		}
	} catch (Exception e) {
	}
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:25,代码来源:WordcountMapper.java

示例10: decodeCsv

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
/**
 * <p>
 * decodeCsv.
 * </p>
 *
 * @param input an array of byte.
 * @param inputLength a int.
 * @param csvFormat a {@link org.apache.commons.csv.CSVFormat} object.
 * @return an array of byte.
 * @throws java.io.IOException if any.
 */
public byte[][] decodeCsv(final byte[] input, final int inputLength, final CSVFormat csvFormat)
        throws IOException
{
    final byte[][] field = new byte[includeColumn.length][];

    try (final CSVParser csvparser = CSVParser.parse(new String(input, 0, inputLength), csvFormat))
    {
        final CSVRecord csvrecord = csvparser.getRecords().get(0);
        final Iterator<String> fields = csvrecord.iterator();
        for (int fNum = 0; fields.hasNext(); fNum++)
        {
            final String fieldAsString = fields.next();

            if (fNum >= includeColumn.length)
                return field;

            if (fNum < includeColumn.length)
                if (includeColumn[fNum])
                    field[fNum] = fieldAsString.getBytes();
        }
        return field;
    }
}
 
开发者ID:fedups,项目名称:com.obdobion.funnelsort,代码行数:35,代码来源:CsvProvider.java

示例11: loadAnnotatedSample

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public void loadAnnotatedSample(String sID, File file)
{
    String fn = file.getName();
    System.out.println("Loading result file: " + fn);
    try {
        List<EnrichmentAnnotation> sample = getSample(sID);

        CSVParser parser = CSVParser.parse(file, Charset.forName("UTF-8")
                                         , CSVFormat.EXCEL);

        Iterator<CSVRecord> iter = parser.iterator();
        if ( iter.hasNext() ) { iter.next(); }

        while (iter.hasNext()) { loadAnnotation(sID, sample, iter.next()); }
    }
    catch (IOException e) {
        System.err.println("Error loading file: " + fn);
    }
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:20,代码来源:EnrichmentSamplesAssembler.java

示例12: exportToCsv

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
@Test
public void exportToCsv() throws E, IOException {
    final R queryRequest = queryRequestBuilderFactory.getObject()
            .queryRestrictions(testUtils.buildQueryRestrictions())
            .queryType(QueryRequest.QueryType.MODIFIED)
            .build();

    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    exportService.exportQueryResults(outputStream, queryRequest, ExportFormat.CSV, Collections.emptyList(), 1001L);
    final String output = outputStream.toString();
    assertNotNull(output);

    try (final CSVParser csvParser = CSVParser.parse(output, CSVFormat.EXCEL)) {
        final List<CSVRecord> records = csvParser.getRecords();
        assertThat(records, not(empty()));
        final CSVRecord headerRecord = records.get(0);
        assertThat(headerRecord.get(0), endsWith("Reference")); // byte-order mark may get in the way
        assertEquals("Database", headerRecord.get(1));
        final CSVRecord firstDataRecord = records.get(1);
        final String firstDataRecordReference = firstDataRecord.get(0);
        assertNotNull(firstDataRecordReference);
        assertFalse(firstDataRecordReference.trim().isEmpty());
        final String firstDataRecordDatabase = firstDataRecord.get(1);
        assertFalse(firstDataRecordDatabase.trim().isEmpty());
    }
}
 
开发者ID:hpe-idol,项目名称:find,代码行数:27,代码来源:PlatformDataExportServiceIT.java

示例13: readFromCsv

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
public static Collection<String[]> readFromCsv(String filename) {
    try {
        CSVParser parser = CSVParser.parse(Utilities.class.getResource(filename), StandardCharsets.UTF_8, CSVFormat.DEFAULT);
        return parser.getRecords().stream()
                .map(csvRecord -> new String[] {csvRecord.get(0), csvRecord.get(1) })
                .collect(Collectors.toList());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:mike-plummer,项目名称:intro-to-junit5,代码行数:11,代码来源:Utilities.java

示例14: doParseDelimited

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
private static String[] doParseDelimited(String delimited, CSVFormat format) {
  try (CSVParser parser = CSVParser.parse(delimited, format)) {
    Iterator<CSVRecord> records = parser.iterator();
    return records.hasNext() ?
        StreamSupport.stream(records.next().spliterator(), false).toArray(String[]::new) :
        EMPTY_STRING;
  } catch (IOException e) {
    throw new IllegalStateException(e); // Can't happen
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:11,代码来源:TextUtils.java

示例15: parseFile

import org.apache.commons.csv.CSVParser; //导入方法依赖的package包/类
static void parseFile(final String fileStr, final PublishSubject<Map<String, String>> subject) throws Exception {

        final CSVParser parser = CSVParser.parse(
            new File(fileStr), StandardCharsets.UTF_8, CSVFormat.DEFAULT
        );

        try {
            parser.forEach(csvRecord -> subject.onNext(toMap(csvRecord)));
            subject.onComplete();
        } finally {
            parser.close();
        }
    }
 
开发者ID:codefacts,项目名称:Elastic-Components,代码行数:14,代码来源:ParseCsv.java


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