Bug 8988 - Check for empty payload properly
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / spi / AbstractIdentifierAwareJaxRsProvider.java
index ac87d2a1e84cd89cb3286120568fe224f0aaa31d..ab40b3274a7197b7dd7bc4261f8d4d0a8fe9db71 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi;
 import com.google.common.base.Optional;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PushbackInputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import javax.ws.rs.HttpMethod;
@@ -47,11 +48,17 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
             final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException,
             WebApplicationException {
         final InstanceIdentifierContext<?> path = getInstanceIdentifierContext();
-        if (entityStream.available() < 1) {
+
+        final PushbackInputStream pushbackInputStream = new PushbackInputStream(entityStream);
+
+        int firstByte = pushbackInputStream.read();
+        if (firstByte == -1) {
             return emptyBody(path);
+        } else {
+            pushbackInputStream.unread(firstByte);
+            return readBody(path, pushbackInputStream);
         }
 
-        return readBody(path, entityStream);
     }
 
     /**