parent
807828b2b7
commit
a63d23492a
|
@ -28,6 +28,7 @@ import com.fasterxml.jackson.core.JsonToken;
|
||||||
import com.fasterxml.jackson.core.async.ByteArrayFeeder;
|
import com.fasterxml.jackson.core.async.ByteArrayFeeder;
|
||||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.util.TokenBuffer;
|
import com.fasterxml.jackson.databind.util.TokenBuffer;
|
||||||
|
import reactor.core.Exceptions;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
import org.springframework.core.codec.DecodingException;
|
import org.springframework.core.codec.DecodingException;
|
||||||
|
@ -74,7 +75,7 @@ final class Jackson2Tokenizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Flux<TokenBuffer> tokenize(DataBuffer dataBuffer) {
|
private List<TokenBuffer> tokenize(DataBuffer dataBuffer) {
|
||||||
byte[] bytes = new byte[dataBuffer.readableByteCount()];
|
byte[] bytes = new byte[dataBuffer.readableByteCount()];
|
||||||
dataBuffer.read(bytes);
|
dataBuffer.read(bytes);
|
||||||
DataBufferUtils.release(dataBuffer);
|
DataBufferUtils.release(dataBuffer);
|
||||||
|
@ -84,27 +85,29 @@ final class Jackson2Tokenizer {
|
||||||
return parseTokenBufferFlux();
|
return parseTokenBufferFlux();
|
||||||
}
|
}
|
||||||
catch (JsonProcessingException ex) {
|
catch (JsonProcessingException ex) {
|
||||||
return Flux.error(new DecodingException("JSON decoding error: " + ex.getOriginalMessage(), ex));
|
throw new DecodingException("JSON decoding error: " + ex.getOriginalMessage(), ex);
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
return Flux.error(ex);
|
throw Exceptions.propagate(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Flux<TokenBuffer> endOfInput() {
|
private Flux<TokenBuffer> endOfInput() {
|
||||||
|
return Flux.defer(() -> {
|
||||||
this.inputFeeder.endOfInput();
|
this.inputFeeder.endOfInput();
|
||||||
try {
|
try {
|
||||||
return parseTokenBufferFlux();
|
return Flux.fromIterable(parseTokenBufferFlux());
|
||||||
}
|
}
|
||||||
catch (JsonProcessingException ex) {
|
catch (JsonProcessingException ex) {
|
||||||
return Flux.error(new DecodingException("JSON decoding error: " + ex.getOriginalMessage(), ex));
|
throw new DecodingException("JSON decoding error: " + ex.getOriginalMessage(), ex);
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
return Flux.error(ex);
|
throw Exceptions.propagate(ex);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Flux<TokenBuffer> parseTokenBufferFlux() throws IOException {
|
private List<TokenBuffer> parseTokenBufferFlux() throws IOException {
|
||||||
List<TokenBuffer> result = new ArrayList<>();
|
List<TokenBuffer> result = new ArrayList<>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -122,7 +125,7 @@ final class Jackson2Tokenizer {
|
||||||
processTokenArray(token, result);
|
processTokenArray(token, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Flux.fromIterable(result);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDepth(JsonToken token) {
|
private void updateDepth(JsonToken token) {
|
||||||
|
@ -184,7 +187,7 @@ final class Jackson2Tokenizer {
|
||||||
try {
|
try {
|
||||||
JsonParser parser = jsonFactory.createNonBlockingByteArrayParser();
|
JsonParser parser = jsonFactory.createNonBlockingByteArrayParser();
|
||||||
Jackson2Tokenizer tokenizer = new Jackson2Tokenizer(parser, deserializationContext, tokenizeArrayElements);
|
Jackson2Tokenizer tokenizer = new Jackson2Tokenizer(parser, deserializationContext, tokenizeArrayElements);
|
||||||
return dataBuffers.flatMap(tokenizer::tokenize, Flux::error, tokenizer::endOfInput);
|
return dataBuffers.concatMapIterable(tokenizer::tokenize).concatWith(tokenizer.endOfInput());
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
return Flux.error(ex);
|
return Flux.error(ex);
|
||||||
|
|
Loading…
Reference in New Issue