Search in sources :

Example 6 with ByteArrayFeeder

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;
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) ByteArrayFeeder(com.fasterxml.jackson.core.async.ByteArrayFeeder)

Example 7 with ByteArrayFeeder

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);
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ByteArrayFeeder(com.fasterxml.jackson.core.async.ByteArrayFeeder)

Example 8 with ByteArrayFeeder

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;
}
Also used : ByteArrayFeeder(com.fasterxml.jackson.core.async.ByteArrayFeeder)

Example 9 with ByteArrayFeeder

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;
}
Also used : ByteArrayFeeder(com.fasterxml.jackson.core.async.ByteArrayFeeder) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

ByteArrayFeeder (com.fasterxml.jackson.core.async.ByteArrayFeeder)9 JsonToken (com.fasterxml.jackson.core.JsonToken)4 IOException (java.io.IOException)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ByteBufferFeeder (com.fasterxml.jackson.core.async.ByteBufferFeeder)1 NonBlockingInputFeeder (com.fasterxml.jackson.core.async.NonBlockingInputFeeder)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1