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


Java CsvReader.parse方法代码示例

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


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

示例1: 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

示例2: 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

示例3: test4

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

	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

示例4: 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

示例5: test70

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test70() throws Exception {
	String data = "\"1\",Bruce\r\n\"2\",Toni\r\n\"3\",Brian\r\n";

	CsvReader reader = CsvReader.parse(data);
	reader.setHeaders(new String[] { "userid", "name" });
	Assert.assertEquals(2, reader.getHeaderCount());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("1", reader.get("userid"));
	Assert.assertEquals("Bruce", reader.get("name"));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("2", reader.get("userid"));
	Assert.assertEquals("Toni", reader.get("name"));
	Assert.assertEquals(1L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("3", reader.get("userid"));
	Assert.assertEquals("Brian", reader.get("name"));
	Assert.assertEquals(2L, reader.getCurrentRecord());
	Assert.assertEquals(2, reader.getColumnCount());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:26,代码来源:AllTests.java

示例6: 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

示例7: test76

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test76() throws Exception {
	CsvReader reader = CsvReader.parse("user_id,name\r\n1,Bruce");
	Assert.assertNull(reader.getHeaders());
	Assert.assertEquals(-1, reader.getIndex("user_id"));
	Assert.assertEquals("", reader.getHeader(0));
	Assert.assertTrue(reader.readHeaders());
	Assert.assertEquals(0, reader.getIndex("user_id"));
	Assert.assertEquals("user_id", reader.getHeader(0));
	String[] headers = reader.getHeaders();
	Assert.assertEquals(2, headers.length);
	Assert.assertEquals("user_id", headers[0]);
	Assert.assertEquals("name", headers[1]);
	reader.setHeaders(null);
	Assert.assertNull(reader.getHeaders());
	Assert.assertEquals(-1, reader.getIndex("user_id"));
	Assert.assertEquals("", reader.getHeader(0));
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:20,代码来源:AllTests.java

示例8: test52

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test52() throws Exception {
	String data = "\\xfa\\u0afa\\xFA\\u0AFA";

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

示例9: test79

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test79() {
	CsvReader reader;
	reader = CsvReader.parse("");
	reader.close();
	try {
		reader.readRecord();
	} catch (Exception ex) {
		assertException(
				new IOException(
						"This instance of the CsvReader class has already been closed."),
				ex);
	}
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:15,代码来源:AllTests.java

示例10: test22

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

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

示例11: test46

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test46() throws Exception {
	String data = "Ch\\icane, Love on the Run, Kn\\ight R\\ider, Th\\is f\\ield conta\\ins an \\i\\, but \\it doesn't matter as \\it \\is escapedi"
			+ "Samuel Barber, Adag\\io for Str\\ings, Class\\ical, Th\\is f\\ield conta\\ins a comma \\, but \\it doesn't matter as \\it \\is escaped";

	CsvReader reader = CsvReader.parse(data);
	reader.setUseTextQualifier(false);
	reader.setEscapeMode(CsvReader.ESCAPE_MODE_BACKSLASH);
	reader.setRecordDelimiter('i');
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("Chicane", reader.get(0));
	Assert.assertEquals("Love on the Run", reader.get(1));
	Assert.assertEquals("Knight Rider", reader.get(2));
	Assert
			.assertEquals(
					"This field contains an i, but it doesn't matter as it is escaped",
					reader.get(3));
	Assert.assertEquals(0L, reader.getCurrentRecord());
	Assert.assertEquals(4, reader.getColumnCount());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("Samuel Barber", reader.get(0));
	Assert.assertEquals("Adagio for Strings", reader.get(1));
	Assert.assertEquals("Classical", reader.get(2));
	Assert
			.assertEquals(
					"This field contains a comma , but it doesn't matter as it is escaped",
					reader.get(3));
	Assert.assertEquals(1L, reader.getCurrentRecord());
	Assert.assertEquals(4, reader.getColumnCount());
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:33,代码来源:AllTests.java

示例12: test29

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test29() throws Exception {
	String data = "\"double\\\"\\\"double quotes\"";

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

示例13: test12

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

	CsvReader reader = CsvReader.parse(data);
	reader.setTrimWhitespace(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.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:15,代码来源:AllTests.java

示例14: test36

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test36() throws Exception {
	String data = "\"some \\stuff\"";

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

示例15: test146

import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test146() throws Exception {
	// testing SkipLine's buffer
	CsvReader reader = CsvReader.parse("\"" + generateString('a', 10000)
			+ "\r\nb");
	Assert.assertEquals("", reader.getRawRecord());
	Assert.assertTrue(reader.skipLine());
	Assert.assertEquals("", reader.getRawRecord());
	Assert.assertTrue(reader.readRecord());
	Assert.assertEquals("b", reader.get(0));
	Assert.assertFalse(reader.readRecord());
	reader.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:14,代码来源:AllTests.java


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