Class BufferedHttpEntity

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, org.apache.hc.core5.http.EntityDetails, org.apache.hc.core5.http.HttpEntity

    public class BufferedHttpEntity
    extends org.apache.hc.core5.http.io.entity.HttpEntityWrapper
    NOTE: This is a copy of org.apache.hc.core5.http.io.entity.BufferedHttpEntity that uses the modified writeTo that can abort the connection instead of entity.writeTo that forcefully reads the connection InputStream to the end and prevented the thread from being interrupted. A wrapping entity that buffers it content if necessary. The buffered entity is always repeatable. If the wrapped entity is repeatable itself, calls are passed through. If the wrapped entity is not repeatable, the content is read into a buffer once and provided from there as often as required.
    Since:
    17.0.0
    • Constructor Summary

      Constructors 
      Constructor Description
      BufferedHttpEntity​(org.apache.hc.core5.http.HttpEntity entity, org.apache.hc.core5.http.ClassicHttpResponse classicHttpResponse, java.util.concurrent.atomic.AtomicBoolean requestTimedOut)
      Creates a new buffered entity wrapper.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.InputStream getContent()  
      long getContentLength()  
      boolean isChunked()
      Tells that this entity does not have to be chunked.
      boolean isRepeatable()
      Tells that this entity is repeatable.
      boolean isStreaming()  
      void writeTo​(java.io.OutputStream outStream)  
      static void writeTo​(org.apache.hc.core5.http.HttpEntity entity, java.io.OutputStream outStream, org.apache.hc.core5.http.ClassicHttpResponse classicHttpResponse, java.util.concurrent.atomic.AtomicBoolean requestTimedOut)
      Writes the entity content out to the output stream while checking if a hard timeout has occured.
      • Methods inherited from class org.apache.hc.core5.http.io.entity.HttpEntityWrapper

        close, getContentEncoding, getContentType, getTrailerNames, getTrailers, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • BufferedHttpEntity

        public BufferedHttpEntity​(org.apache.hc.core5.http.HttpEntity entity,
                                  org.apache.hc.core5.http.ClassicHttpResponse classicHttpResponse,
                                  java.util.concurrent.atomic.AtomicBoolean requestTimedOut)
                           throws java.io.IOException,
                                  java.lang.InterruptedException
        Creates a new buffered entity wrapper.
        Parameters:
        entity - the entity to wrap, not null
        classicHttpResponse - the response to abort, not null
        requestTimedOut - atomic boolean that identifies if a hard timeout has occured and the request should be canceled
        Throws:
        java.lang.IllegalArgumentException - if wrapped is null
        java.io.IOException - if an I/O error occurs or the request is interrupted and connection aborted
        java.lang.InterruptedException
    • Method Detail

      • writeTo

        public static void writeTo​(org.apache.hc.core5.http.HttpEntity entity,
                                   java.io.OutputStream outStream,
                                   org.apache.hc.core5.http.ClassicHttpResponse classicHttpResponse,
                                   java.util.concurrent.atomic.AtomicBoolean requestTimedOut)
                            throws java.io.IOException
        Writes the entity content out to the output stream while checking if a hard timeout has occured. In case of a hard timeout, the response connection is aborted before any transfer can be finalized.
        Parameters:
        entity - the entity
        outStream - target output stream to write the entity to
        classicHttpResponse - the response that will be aborted in case of a hard timeout
        requestTimedOut - atomic boolean that identifies if a hard timeout has occured and the request should be canceled
        Throws:
        java.io.IOException - if an I/O error occurs or the request is interrupted and connection aborted
      • getContentLength

        public long getContentLength()
        Specified by:
        getContentLength in interface org.apache.hc.core5.http.EntityDetails
        Overrides:
        getContentLength in class org.apache.hc.core5.http.io.entity.HttpEntityWrapper
      • getContent

        public java.io.InputStream getContent()
                                       throws java.io.IOException
        Specified by:
        getContent in interface org.apache.hc.core5.http.HttpEntity
        Overrides:
        getContent in class org.apache.hc.core5.http.io.entity.HttpEntityWrapper
        Throws:
        java.io.IOException
      • isChunked

        public boolean isChunked()
        Tells that this entity does not have to be chunked.
        Specified by:
        isChunked in interface org.apache.hc.core5.http.EntityDetails
        Overrides:
        isChunked in class org.apache.hc.core5.http.io.entity.HttpEntityWrapper
        Returns:
        false
      • isRepeatable

        public boolean isRepeatable()
        Tells that this entity is repeatable.
        Specified by:
        isRepeatable in interface org.apache.hc.core5.http.HttpEntity
        Overrides:
        isRepeatable in class org.apache.hc.core5.http.io.entity.HttpEntityWrapper
        Returns:
        true
      • writeTo

        public void writeTo​(java.io.OutputStream outStream)
                     throws java.io.IOException
        Specified by:
        writeTo in interface org.apache.hc.core5.http.HttpEntity
        Overrides:
        writeTo in class org.apache.hc.core5.http.io.entity.HttpEntityWrapper
        Throws:
        java.io.IOException
      • isStreaming

        public boolean isStreaming()
        Specified by:
        isStreaming in interface org.apache.hc.core5.http.HttpEntity
        Overrides:
        isStreaming in class org.apache.hc.core5.http.io.entity.HttpEntityWrapper