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


Java CsvReader类代码示例

本文整理汇总了Java中com.csvreader.CsvReader的典型用法代码示例。如果您正苦于以下问题:Java CsvReader类的具体用法?Java CsvReader怎么用?Java CsvReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test10

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test10() throws Exception {
	String data = "1\r2\n";

	CsvReader reader = CsvReader.parse(data);
	reader.setDelimiter('\r');
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals("2", reader.get(1));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertEquals("1\r2", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	Assert.assertEquals("", reader.getRawRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:17,代码来源:AllTests.java

示例2: Test174

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void Test174() throws IOException {
	// verifies that data is eventually automatically flushed
	CsvWriter writer = new CsvWriter("temp.csv");
	
	for (int i = 0; i < 10000; i++)
	{
		writer.write("stuff");
		writer.endRecord();
	}
	
	CsvReader reader = new CsvReader("temp.csv");
	
	Assert.assertTrue(reader.readRecord());
	
	Assert.assertEquals("stuff", reader.get(0));
	
	writer.close();
	reader.close();

	new File("temp.csv").delete();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:23,代码来源:AllTests.java

示例3: test1

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test1() throws Exception {
	CsvReader reader = CsvReader.parse("1,2");
	Assert.assertEquals("", reader.getRawRecord());
	Assert.assertEquals("", reader.get(0));
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals("2", reader.get(1));
	Assert.assertEquals(',', reader.getDelimiter());
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertEquals("1,2", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	Assert.assertEquals("", reader.getRawRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:17,代码来源:AllTests.java

示例4: test2

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test2() throws Exception {
	String data = "\"bob said, \"\"Hey!\"\"\",2, 3 ";

	CsvReader reader = CsvReader.parse(data);
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("bob said, \"Hey!\"", reader.get(0));
	Assert.assertEquals("2", reader.get(1));
	Assert.assertEquals("3", reader.get(2));
	Assert.assertEquals(',', reader.getDelimiter());
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(3, reader.getColumnCount());
	Assert.assertEquals("\"bob said, \"\"Hey!\"\"\",2, 3 ", reader
			.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	Assert.assertEquals("", reader.getRawRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:19,代码来源:AllTests.java

示例5: test3

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test3() throws Exception {
	String data = ",";

	CsvReader reader = CsvReader.parse(data);
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("", reader.get(0));
	Assert.assertEquals("", reader.get(1));
	Assert.assertEquals(',', reader.getDelimiter());
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertEquals(",", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	Assert.assertEquals("", reader.getRawRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:17,代码来源:AllTests.java

示例6: test6

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test6() throws Exception {
	String data = "1\r\n2";

	CsvReader reader = CsvReader.parse(data);
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(1, reader.getColumnCount());
	Assert.assertEquals("1", reader.getRawRecord());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("2", reader.get(0));
	Assert.assertEquals(1L, reader.getCurrentRecord());
	Assert.assertEquals(1, reader.getColumnCount());
	Assert.assertEquals("2", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	Assert.assertEquals("", reader.getRawRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:20,代码来源:AllTests.java

示例7: test14

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test14() throws Exception {
	String data = "user_id,name\r\n1,Bruce";

	CsvReader reader = CsvReader.parse(data);
	Assert.assertTrue(reader.readHeaders());
	Assert.assertEquals("user_id,name", reader.getRawRecord());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals("Bruce", reader.get(1));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertEquals(0, reader.getIndex("user_id"));
	Assert.assertEquals(1, reader.getIndex("name"));
	Assert.assertEquals("user_id", reader.getHeader(0));
	Assert.assertEquals("name", reader.getHeader(1));
	Assert.assertEquals("1", reader.get("user_id"));
	Assert.assertEquals("Bruce", reader.get("name"));
	Assert.assertEquals("1,Bruce", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:23,代码来源:AllTests.java

示例8: test16

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test16() throws Exception {
	String data = "\r\r\n1\r";

	CsvReader reader = CsvReader.parse(data);
	reader.setDelimiter('\r');
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("", reader.get(0));
	Assert.assertEquals("", reader.get(1));
	Assert.assertEquals("", reader.get(2));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(3, reader.getColumnCount());
	Assert.assertEquals("\r\r", reader.getRawRecord());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals("", reader.get(1));
	Assert.assertEquals(1L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertEquals("1\r", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:23,代码来源:AllTests.java

示例9: test148

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test148() throws Exception {
	// testing a specific case in GetRawRecord where the result is what's in
	// the data buffer
	// plus what's in the raw buffer
	CsvReader reader = CsvReader.parse("\"" + generateString('a', 100000)
			+ "\"\r\n" + generateString('a', 100000));
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals(generateString('a', 100000), reader.get(0));
	Assert.assertEquals("\"" + generateString('a', 100000) + "\"", reader
			.getRawRecord());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals(generateString('a', 100000), reader.get(0));
	Assert.assertEquals(generateString('a', 100000), reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:18,代码来源:AllTests.java

示例10: test21

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test21() throws Exception {
	String data = "'bob said, ''Hey!''',2, 3 ";

	CsvReader reader = CsvReader.parse(data);
	reader.setTextQualifier('\'');
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("bob said, 'Hey!'", reader.get(0));
	Assert.assertEquals("2", reader.get(1));
	Assert.assertEquals("3", reader.get(2));
	Assert.assertEquals(',', reader.getDelimiter());
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(3, reader.getColumnCount());
	Assert
			.assertEquals("'bob said, ''Hey!''',2, 3 ", reader
					.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:20,代码来源:AllTests.java

示例11: test23

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test23() throws Exception {
	String data = generateString('a', 75) + "," + generateString('b', 75);

	CsvReader reader = CsvReader.parse(data);
	reader.setUseTextQualifier(false);
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals(reader.get(0), generateString('a', 75));
	Assert.assertEquals(reader.get(1), generateString('b', 75));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertEquals(generateString('a', 75) + ","
			+ generateString('b', 75), reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:17,代码来源:AllTests.java

示例12: test24

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test24() throws Exception {
	String data = "1\r\n\r\n1";

	CsvReader reader = CsvReader.parse(data);
	reader.setUseTextQualifier(false);
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(1, reader.getColumnCount());
	Assert.assertEquals("1", reader.getRawRecord());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals(1L, reader.getCurrentRecord());
	Assert.assertEquals(1, reader.getColumnCount());
	Assert.assertEquals("1", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:20,代码来源:AllTests.java

示例13: test25

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test25() throws Exception {
	String data = "1\r\n# bunch of crazy stuff here\r\n1";

	CsvReader reader = CsvReader.parse(data);
	reader.setUseTextQualifier(false);
	reader.setUseComments(true);
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(1, reader.getColumnCount());
	Assert.assertEquals("1", reader.getRawRecord());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get(0));
	Assert.assertEquals(1L, reader.getCurrentRecord());
	Assert.assertEquals(1, reader.getColumnCount());
	Assert.assertEquals("1", reader.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:21,代码来源:AllTests.java

示例14: getBolusNormal

import com.csvreader.CsvReader; //导入依赖的package包/类
/**
 * Returns the normal bolus for the given CsvReader.
 *
 * @param creader The CsvReader instance.
 * @return String The normal bolus.
 * @throws IOException If the file could not be opened.
 * @throws ParseException If there was an error while parsing.
 */
public String getBolusNormal(final CsvReader creader) throws IOException, ParseException {
    String tempMeal = getInsulinMeal(creader);
    String tempCorrection = getInsulinCorrection(creader);
    String tempPen = getInsulinPen(creader);
    String tempPump = getInsulinPump(creader);
    int insulinMeal = 0, insulinCorrection = 0, insulinPen = 0, insulinPump = 0;
    if (!tempMeal.isEmpty()) {
        insulinMeal = Integer.valueOf(tempMeal);
    }
    if (!tempCorrection.isEmpty()) {
        insulinCorrection = Integer.valueOf(tempCorrection);
    }
    if (!tempPen.isEmpty()) {
        insulinPen = Integer.valueOf(tempPen);
    }
    if (!tempPump.isEmpty()) {
        insulinPump = Integer.valueOf(tempPump);
    }
    if (insulinMeal + insulinCorrection + insulinPen + insulinPump != 0) {
        return Integer.toString(insulinMeal + insulinCorrection + insulinPen + insulinPump);
    }

    return "";
}
 
开发者ID:lucasbuschlinger,项目名称:BachelorPraktikum,代码行数:33,代码来源:MySugrCSVValidator.java

示例15: test28

import com.csvreader.CsvReader; //导入依赖的package包/类
@Test
public void test28() throws Exception {
	String data = "\"bob said, \\\"Hey!\\\"\",2, 3 ";

	CsvReader reader = CsvReader.parse(data);
	reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("bob said, \"Hey!\"", reader.get(0));
	Assert.assertEquals("2", reader.get(1));
	Assert.assertEquals("3", reader.get(2));
	Assert.assertEquals(',', reader.getDelimiter());
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(3, reader.getColumnCount());
	Assert.assertEquals("\"bob said, \\\"Hey!\\\"\",2, 3 ", reader
			.getRawRecord());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:19,代码来源:AllTests.java


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