本文整理匯總了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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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 "";
}
示例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();
}