|
19 | 19 | import java.io.IOException; |
20 | 20 | import java.io.InputStream; |
21 | 21 | import java.io.OutputStream; |
22 | | -import java.io.PushbackInputStream; |
23 | 22 | import java.lang.annotation.Annotation; |
24 | 23 | import java.lang.reflect.Type; |
25 | 24 |
|
|
41 | 40 |
|
42 | 41 | import org.glassfish.jersey.jsonb.LocalizationMessages; |
43 | 42 | import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider; |
| 43 | +import org.glassfish.jersey.message.internal.EntityInputStream; |
44 | 44 |
|
45 | 45 | /** |
46 | 46 | * Entity provider (reader and writer) for JSONB. |
@@ -72,20 +72,10 @@ public Object readFrom(Class<Object> type, Type genericType, |
72 | 72 | MediaType mediaType, |
73 | 73 | MultivaluedMap<String, String> httpHeaders, |
74 | 74 | InputStream entityStream) throws IOException, WebApplicationException { |
75 | | - if (entityStream.markSupported()) { |
76 | | - entityStream.mark(1); |
77 | | - if (entityStream.read() == -1) { |
78 | | - throw new NoContentException(LocalizationMessages.ERROR_JSONB_EMPTYSTREAM()); |
79 | | - } |
80 | | - entityStream.reset(); |
81 | | - } else { |
82 | | - final PushbackInputStream buffer = new PushbackInputStream(entityStream); |
83 | | - final int firstByte = buffer.read(); |
84 | | - if (firstByte == -1) { |
85 | | - throw new NoContentException(LocalizationMessages.ERROR_JSONB_EMPTYSTREAM()); |
86 | | - } |
87 | | - buffer.unread(firstByte); |
88 | | - entityStream = buffer; |
| 75 | + final EntityInputStream entityInputStream = new EntityInputStream(entityStream); |
| 76 | + entityStream = entityInputStream; |
| 77 | + if (entityInputStream.isEmpty()) { |
| 78 | + throw new NoContentException(LocalizationMessages.ERROR_JSONB_EMPTYSTREAM()); |
89 | 79 | } |
90 | 80 |
|
91 | 81 | Jsonb jsonb = getJsonb(type); |
|
0 commit comments