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);
}
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);
}
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);
}
Aggregations