Search in sources :

Example 1 with CsvReader

use of org.spf4j.io.csv.CsvReader in project spf4j by zolyfarkas.

the class CsvTest method testCsvStream1n1.

@Test
public void testCsvStream1n1() throws IOException, CsvParseException {
    CsvReader reader = Csv.readerNoBOM(new PushbackReader(new StringReader(",")));
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("", reader.getElement().toString());
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("", reader.getElement().toString());
    Assert.assertEquals(TokenType.END_ROW, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
}
Also used : CsvReader(org.spf4j.io.csv.CsvReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 2 with CsvReader

use of org.spf4j.io.csv.CsvReader in project spf4j by zolyfarkas.

the class CsvTest method testCsvStream4.

@Test
public void testCsvStream4() throws IOException, CsvParseException {
    CsvReader reader = Csv.readerNoBOM(new PushbackReader(new StringReader("bla,\"bla\"\n")));
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("bla", reader.getElement().toString());
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("bla", reader.getElement().toString());
    Assert.assertEquals(TokenType.END_ROW, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
}
Also used : CsvReader(org.spf4j.io.csv.CsvReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 3 with CsvReader

use of org.spf4j.io.csv.CsvReader in project spf4j by zolyfarkas.

the class CsvTest method testCsvStream5.

@Test
public void testCsvStream5() throws IOException, CsvParseException {
    CsvReader reader = Csv.reader(new StringReader("bla,\"bla\"\nuhu,uhu2\n"));
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("bla", reader.getElement().toString());
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("bla", reader.getElement().toString());
    Assert.assertEquals(TokenType.END_ROW, reader.next());
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("uhu", reader.getElement().toString());
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("uhu2", reader.getElement().toString());
    Assert.assertEquals(TokenType.END_ROW, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
}
Also used : CsvReader(org.spf4j.io.csv.CsvReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 4 with CsvReader

use of org.spf4j.io.csv.CsvReader in project spf4j by zolyfarkas.

the class CsvTest method testCsvFileParsingReader2.

@Test
public void testCsvFileParsingReader2() throws IOException, CsvParseException {
    try (InputStream resourceAsStream = CsvTest.class.getResourceAsStream("/test.csv")) {
        CsvReader reader = Csv.reader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8));
        CsvReader.TokenType token;
        while ((token = reader.next()) != TokenType.END_DOCUMENT) {
            LOG.debug("Token {}", token);
        }
        Assert.assertNotNull(reader);
    }
}
Also used : CsvReader(org.spf4j.io.csv.CsvReader) TokenType(org.spf4j.io.csv.CsvReader.TokenType) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with CsvReader

use of org.spf4j.io.csv.CsvReader in project spf4j by zolyfarkas.

the class CsvTest method testCsvStream1.

@Test
public void testCsvStream1() throws IOException, CsvParseException {
    CsvReader reader = Csv.readerNoBOM(new PushbackReader(new StringReader("")));
    Assert.assertEquals(TokenType.ELEMENT, reader.next());
    Assert.assertEquals("", reader.getElement().toString());
    Assert.assertEquals(TokenType.END_ROW, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
    Assert.assertEquals(TokenType.END_DOCUMENT, reader.next());
}
Also used : CsvReader(org.spf4j.io.csv.CsvReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

CsvReader (org.spf4j.io.csv.CsvReader)10 Test (org.junit.Test)8 StringReader (java.io.StringReader)6 InputStreamReader (java.io.InputStreamReader)3 AvroRuntimeException (org.apache.avro.AvroRuntimeException)2 Schema (org.apache.avro.Schema)2 DecodedSchema (org.spf4j.avro.DecodedSchema)2 CsvParseException (org.spf4j.io.csv.CsvParseException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 TokenType (org.spf4j.io.csv.CsvReader.TokenType)1