Class EntityInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    InboundMessageContext.EntityContent

    public class EntityInputStream
    extends java.io.InputStream
    Entity input stream customized for entity message processing:
    • contains isEmpty() method.
    • close() method throws Jersey-specific runtime exception in case of an IO error.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean closed  
      private java.io.InputStream input  
    • Constructor Summary

      Constructors 
      Constructor Description
      EntityInputStream​(java.io.InputStream input)
      Extension constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()
      static EntityInputStream create​(java.io.InputStream inputStream)
      Create an entity input stream instance wrapping the original input stream.
      void ensureNotClosed()
      Check that the entity input stream has not been closed yet.
      java.io.InputStream getWrappedStream()
      Get the wrapped input stream instance.
      boolean isClosed()
      Get the closed status of this input stream.
      boolean isEmpty()
      Check if the underlying entity stream is empty.
      void mark​(int readLimit)  
      boolean markSupported()  
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int off, int len)  
      void reset()
      void setWrappedStream​(java.io.InputStream wrapped)
      Set the wrapped input stream instance.
      long skip​(long n)  
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • input

        private java.io.InputStream input
      • closed

        private boolean closed
    • Constructor Detail

      • EntityInputStream

        public EntityInputStream​(java.io.InputStream input)
        Extension constructor.
        Parameters:
        input - underlying wrapped input stream.
    • Method Detail

      • create

        public static EntityInputStream create​(java.io.InputStream inputStream)
        Create an entity input stream instance wrapping the original input stream.

        In case the original entity stream is already of type EntityInputStream, the stream is returned without wrapping.

        Parameters:
        inputStream - input stream.
        Returns:
        entity input stream.
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • mark

        public void mark​(int readLimit)
        Overrides:
        mark in class java.io.InputStream
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class java.io.InputStream
      • reset

        public void reset()

        The method is customized to not throw an IOException if the reset operation fails. Instead, a runtime ProcessingException is thrown.

        Overrides:
        reset in class java.io.InputStream
        Throws:
        javax.ws.rs.ProcessingException - in case the reset operation on the underlying entity input stream failed.
      • close

        public void close()
                   throws javax.ws.rs.ProcessingException

        The method is customized to not throw an IOException if the close operation fails. Instead, a warning message is logged.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        javax.ws.rs.ProcessingException
      • isEmpty

        public boolean isEmpty()
        Check if the underlying entity stream is empty.

        Note that the operation may need to block until a first byte (or EOF) is available in the stream.

        Returns:
        true if the entity stream is empty, false otherwise.
      • ensureNotClosed

        public void ensureNotClosed()
                             throws java.lang.IllegalStateException
        Check that the entity input stream has not been closed yet.
        Throws:
        java.lang.IllegalStateException - in case the entity input stream has been closed.
      • isClosed

        public boolean isClosed()
        Get the closed status of this input stream.
        Returns:
        true if the stream has been closed, false otherwise.
      • getWrappedStream

        public final java.io.InputStream getWrappedStream()
        Get the wrapped input stream instance.
        Returns:
        wrapped input stream instance.
      • setWrappedStream

        public final void setWrappedStream​(java.io.InputStream wrapped)
        Set the wrapped input stream instance.
        Parameters:
        wrapped - new input stream instance to be wrapped.