Skip to content

Commit 1c3b8d5

Browse files
senivamjansupol
authored andcommitted
use EntityInputStream to check if stream is empty
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
1 parent b17b3ea commit 1c3b8d5

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.io.OutputStream;
22-
import java.io.PushbackInputStream;
2322
import java.lang.annotation.Annotation;
2423
import java.lang.reflect.Type;
2524

@@ -41,6 +40,7 @@
4140

4241
import org.glassfish.jersey.jsonb.LocalizationMessages;
4342
import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider;
43+
import org.glassfish.jersey.message.internal.EntityInputStream;
4444

4545
/**
4646
* Entity provider (reader and writer) for JSONB.
@@ -72,20 +72,10 @@ public Object readFrom(Class<Object> type, Type genericType,
7272
MediaType mediaType,
7373
MultivaluedMap<String, String> httpHeaders,
7474
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());
8979
}
9080

9181
Jsonb jsonb = getJsonb(type);

0 commit comments

Comments
 (0)