use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project eol-globi-data by jhpoelen.
the class ResultFormatterSeparatedValues method handleRows.
private void handleRows(OutputStream os, JsonParser jsonParser) throws IOException {
JsonToken token;
token = jsonParser.nextToken();
if (START_ARRAY.equals(token)) {
boolean isFirstValue = true;
boolean inValueArray = false;
boolean inRowArray = false;
String currentFieldName = null;
ByteArrayOutputStream lineBuffer = new ByteArrayOutputStream();
while ((token = jsonParser.nextToken()) != null) {
if (FIELD_NAME.equals(token)) {
currentFieldName = jsonParser.getCurrentName();
}
if (START_ARRAY.equals(token)) {
if (inRowArray && !StringUtils.equals("meta", currentFieldName)) {
inValueArray = true;
} else {
isFirstValue = true;
inRowArray = true;
}
} else if (isValue(token)) {
if (!isFirstValue && !inValueArray) {
if (!StringUtils.equals("meta", currentFieldName)) {
IOUtils.write(getFieldSeparator(), lineBuffer, StandardCharsets.UTF_8);
}
}
if (inValueArray) {
if (lineBuffer.size() > 0) {
lineBuffer.writeTo(os);
IOUtils.write(getFieldSeparator(), os, StandardCharsets.UTF_8);
writeValue(os, jsonParser, token);
addNewline(os);
}
} else {
writeValue(lineBuffer, jsonParser, token);
}
isFirstValue = false;
} else if (END_ARRAY.equals(token)) {
if (inValueArray) {
inValueArray = false;
} else if (inRowArray) {
if (lineBuffer.size() > 0) {
addNewline(lineBuffer);
lineBuffer.writeTo(os);
}
inRowArray = false;
}
lineBuffer = new ByteArrayOutputStream();
}
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project eol-globi-data by jhpoelen.
the class ResultFormatterSeparatedValues method format.
@Override
public void format(InputStream is, OutputStream os) throws ResultFormattingException {
try (InputStream inputStream = is) {
JsonFactory factory = new JsonFactory();
JsonParser jsonParser = factory.createJsonParser(inputStream);
JsonToken token;
while (!jsonParser.isClosed() && (token = jsonParser.nextToken()) != null) {
if (FIELD_NAME.equals(token) && "columns".equals(jsonParser.getCurrentName())) {
handleHeader(os, jsonParser);
} else if (FIELD_NAME.equals(token) && "data".equals(jsonParser.getCurrentName())) {
handleRows(os, jsonParser);
}
}
} catch (IOException e) {
throw new ResultFormattingException("failed to format incoming stream", e);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project eol-globi-data by jhpoelen.
the class ResultFormatterSeparatedValues method handleHeader.
public void handleHeader(OutputStream os, JsonParser jsonParser) throws IOException {
JsonToken token;
token = jsonParser.nextToken();
if (START_ARRAY.equals(token)) {
boolean isFirstValue = true;
while ((token = jsonParser.nextToken()) != null && !END_ARRAY.equals(token)) {
if (isValue(token)) {
if (!isFirstValue) {
IOUtils.write(getFieldSeparator(), os, StandardCharsets.UTF_8);
}
writeValue(os, jsonParser, token);
isFirstValue = false;
}
}
addNewline(os);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project curiostack by curioswitch.
the class TypeSpecificMarshaller method mergeValue.
void mergeValue(JsonParser parser, int currentDepth, Message.Builder builder) throws IOException {
ParseSupport.checkRecursionLimit(currentDepth);
JsonToken json = parser.currentToken();
if (json == null) {
// Nested messages will already have current token set, but top-level ones will not.
json = parser.nextToken();
}
if (json != JsonToken.START_OBJECT) {
throw new InvalidProtocolBufferException("Expected start of object, got: " + parser.getText());
}
doMerge(parser, currentDepth, builder);
// Object end will be handled in ParseSupport.checkObjectEnd.
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project curiostack by curioswitch.
the class ParseSupport method parseArrayStart.
/**
* Checks whether the current token is '[' and advances past it.
*/
public static void parseArrayStart(JsonParser parser) throws IOException {
JsonToken json = parser.currentToken();
if (json != JsonToken.START_ARRAY) {
throw new InvalidProtocolBufferException("Expected an array but found: " + json);
}
parser.nextToken();
}
Aggregations