use of com.fasterxml.jackson.core.async.ByteArrayFeeder in project jackson-core by FasterXML.
the class AsyncReaderWrapperForByteArray method nextToken.
@Override
public JsonToken nextToken() {
JsonToken token;
while ((token = _streamReader.nextToken()) == JsonToken.NOT_AVAILABLE) {
ByteArrayFeeder feeder = (ByteArrayFeeder) _streamReader.nonBlockingInputFeeder();
if (!feeder.needMoreInput()) {
throw new StreamReadException(null, "Got NOT_AVAILABLE, could not feed more input");
}
int amount = Math.min(_bytesPerFeed, _end - _offset);
if (amount < 1) {
// end-of-input?
feeder.endOfInput();
} else {
// padding?
if (_padding == 0) {
feeder.feedInput(_doc, _offset, _offset + amount);
} else {
byte[] tmp = new byte[amount + _padding + _padding];
System.arraycopy(_doc, _offset, tmp, _padding, amount);
feeder.feedInput(tmp, _padding, _padding + amount);
}
_offset += amount;
}
}
return token;
}
use of com.fasterxml.jackson.core.async.ByteArrayFeeder in project micronaut-core by micronaut-projects.
the class JacksonProcessor method onUpstreamMessage.
@Override
protected void onUpstreamMessage(byte[] message) {
if (LOG.isTraceEnabled()) {
LOG.trace("Received upstream bytes of length: " + message.length);
}
try {
if (message.length == 0) {
if (needMoreInput()) {
requestMoreInput();
}
return;
}
final ByteArrayFeeder byteFeeder = byteFeeder(message);
JsonToken event = currentNonBlockingJsonParser.nextToken();
checkForStreaming(event);
while (event != JsonToken.NOT_AVAILABLE) {
final JsonNode root = asJsonNode(event);
if (root != null) {
final boolean isLast = nodeStack.isEmpty() && !jsonStream;
if (isLast) {
byteFeeder.endOfInput();
if (streamArray && root.isArray()) {
break;
}
}
publishNode(root);
if (isLast) {
break;
}
}
event = currentNonBlockingJsonParser.nextToken();
}
if (jsonStream) {
if (nodeStack.isEmpty()) {
byteFeeder.endOfInput();
}
requestMoreInput();
} else if (needMoreInput()) {
requestMoreInput();
}
} catch (IOException e) {
onError(e);
}
}
use of com.fasterxml.jackson.core.async.ByteArrayFeeder in project micronaut-core by micronaut-projects.
the class JacksonCoreProcessor method byteFeeder.
private ByteArrayFeeder byteFeeder(byte[] message) throws IOException {
ByteArrayFeeder byteFeeder = currentNonBlockingJsonParser.getNonBlockingInputFeeder();
final boolean needMoreInput = byteFeeder.needMoreInput();
if (!needMoreInput) {
currentNonBlockingJsonParser = (NonBlockingJsonParser) jsonFactory.createNonBlockingByteArrayParser();
byteFeeder = currentNonBlockingJsonParser.getNonBlockingInputFeeder();
}
byteFeeder.feedInput(message, 0, message.length);
return byteFeeder;
}
use of com.fasterxml.jackson.core.async.ByteArrayFeeder in project jackson-benchmarks by FasterXML.
the class SmileStdReadAsync method read.
@Override
protected Object read(byte[] input, ObjectReader reader) throws IOException {
JsonParser p = MAPPER.createNonBlockingByteArrayParser();
((ByteArrayFeeder) p.nonBlockingInputFeeder()).feedInput(input, 0, input.length);
Object result = reader.readValue(p);
p.close();
return result;
}
Aggregations