Search in sources :

Example 1 with PushbackReader

use of org.spf4j.io.PushbackReader in project spf4j by zolyfarkas.

the class Configs method parseHeader.

private static ConfigHeader parseHeader(@WillNotClose final Reader reader, final Schema rSchema, final SchemaResolver schemaResolver) throws IOException {
    Schema wSchema;
    MediaType mt;
    PushbackReader pbr = new PushbackReader(reader);
    int firstChar = pbr.read();
    if (firstChar < 0) {
        mt = MediaType.JSON_UTF_8;
        Reader r = pbr;
        wSchema = rSchema;
        return new ConfigHeader(wSchema, r, mt);
    }
    BufferedReader content;
    Adapter adapter = AvroCompatUtils.getAdapter();
    if (firstChar == '#') {
        content = new BufferedReader(pbr);
        String header = content.readLine();
        if (header == null) {
            mt = MediaType.JSON_UTF_8;
            pbr.unread(firstChar);
            Reader r = pbr;
            wSchema = rSchema;
            return new ConfigHeader(wSchema, r, mt);
        }
        mt = getConfigMediaType(header);
        if (mt != null) {
            List<String> schemaStrList = mt.parameters().get("avsc");
            if (schemaStrList.isEmpty()) {
                wSchema = rSchema;
            } else {
                wSchema = adapter.parseSchema(new StringReader(schemaStrList.get(0)), true, schemaResolver);
            }
        } else {
            mt = MediaType.create(header, header);
            wSchema = rSchema;
        }
    } else {
        mt = MediaType.JSON_UTF_8;
        pbr.unread(firstChar);
        content = new BufferedReader(pbr);
        wSchema = rSchema;
    }
    return new ConfigHeader(wSchema, content, mt);
}
Also used : Schema(org.apache.avro.Schema) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) MediaType(com.google.common.net.MediaType) Reader(java.io.Reader) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) DatumReader(org.apache.avro.io.DatumReader) StringReader(java.io.StringReader) PushbackReader(org.spf4j.io.PushbackReader) BufferedReader(java.io.BufferedReader) PushbackReader(org.spf4j.io.PushbackReader)

Example 2 with PushbackReader

use of org.spf4j.io.PushbackReader in project spf4j by zolyfarkas.

the class CharSeparatedValues method reader.

public CsvReader reader(final Reader preader) throws IOException {
    PushbackReader reader = new PushbackReader(preader);
    int firstChar = reader.read();
    if (firstChar != UTF_BOM && firstChar >= 0) {
        reader.unread(firstChar);
    }
    return readerNoBOMILEL(reader);
}
Also used : PushbackReader(org.spf4j.io.PushbackReader)

Example 3 with PushbackReader

use of org.spf4j.io.PushbackReader in project spf4j by zolyfarkas.

the class CharSeparatedValues method read.

public <T> T read(final Reader preader, final CsvHandler<T> handler) throws IOException, CsvParseException {
    PushbackReader reader = new PushbackReader(preader);
    int firstChar = reader.read();
    if (firstChar != UTF_BOM && firstChar >= 0) {
        reader.unread(firstChar);
    }
    return readNoBom(reader, handler);
}
Also used : PushbackReader(org.spf4j.io.PushbackReader)

Aggregations

PushbackReader (org.spf4j.io.PushbackReader)3 MediaType (com.google.common.net.MediaType)1 BufferedReader (java.io.BufferedReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Schema (org.apache.avro.Schema)1 DatumReader (org.apache.avro.io.DatumReader)1 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)1