Class CompressingEntity

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

    public final class CompressingEntity
    extends org.apache.hc.core5.http.io.entity.HttpEntityWrapper
    Streaming wrapper that compresses the enclosed HttpEntity on write.

    The actual compressor is supplied as an IOFunction<OutputStream,OutputStream> and is resolved by the caller (for example via reflective factories). This keeps compression back-ends fully optional and avoids hard classpath dependencies.

    The entity reports the configured Content-Encoding token and streams the content; length is unknown (-1), and the entity is chunked.

    Since:
    5.6
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String coding  
      private org.apache.hc.core5.io.IOFunction<java.io.OutputStream,​java.io.OutputStream> encoder  
    • Constructor Summary

      Constructors 
      Constructor Description
      CompressingEntity​(org.apache.hc.core5.http.HttpEntity src, java.lang.String coding, org.apache.hc.core5.io.IOFunction<java.io.OutputStream,​java.io.OutputStream> encoder)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.InputStream getContent()  
      java.lang.String getContentEncoding()  
      long getContentLength()  
      boolean isChunked()  
      void writeTo​(java.io.OutputStream out)  
      • Methods inherited from class org.apache.hc.core5.http.io.entity.HttpEntityWrapper

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

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

      • encoder

        private final org.apache.hc.core5.io.IOFunction<java.io.OutputStream,​java.io.OutputStream> encoder
      • coding

        private final java.lang.String coding
    • Constructor Detail

      • CompressingEntity

        public CompressingEntity​(org.apache.hc.core5.http.HttpEntity src,
                                 java.lang.String coding,
                                 org.apache.hc.core5.io.IOFunction<java.io.OutputStream,​java.io.OutputStream> encoder)
    • Method Detail

      • getContentEncoding

        public java.lang.String getContentEncoding()
        Specified by:
        getContentEncoding in interface org.apache.hc.core5.http.EntityDetails
        Overrides:
        getContentEncoding in class org.apache.hc.core5.http.io.entity.HttpEntityWrapper
      • 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
      • isChunked

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

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

        public void writeTo​(java.io.OutputStream out)
                     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