com.facebook.presto.jdbc.internal.jackson.datatype.jdk8.IntStreamSerializer Maven / Gradle / Ivy
package com.facebook.presto.jdbc.internal.jackson.datatype.jdk8;
import com.facebook.presto.jdbc.internal.jackson.core.JsonGenerator;
import com.facebook.presto.jdbc.internal.jackson.databind.SerializerProvider;
import com.facebook.presto.jdbc.internal.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
import java.util.stream.IntStream;
/**
* {@link IntStream} serializer
*
* Unfortunately there to common ancestor between number base stream, so we need to define each in a specific class
*
*/
public class IntStreamSerializer extends StdSerializer
{
private static final long serialVersionUID = 1L;
/**
* Singleton instance
*/
public static final IntStreamSerializer INSTANCE = new IntStreamSerializer();
/**
* Constructor
*/
private IntStreamSerializer() {
super(IntStream.class);
}
@Override
public void serialize(IntStream stream, JsonGenerator jgen, SerializerProvider provider) throws IOException {
try(IntStream is = stream) {
jgen.writeStartArray();
is.forEachOrdered(value -> {
try {
jgen.writeNumber(value);
} catch (IOException e) {
throw new WrappedIOException(e);
}
});
jgen.writeEndArray();
} catch (WrappedIOException e) {
throw e.getCause();
}
}
}