Class RepeatableInputStreamRequestEntity

  • All Implemented Interfaces:
    org.apache.http.HttpEntity

    public class RepeatableInputStreamRequestEntity
    extends org.apache.http.entity.BasicHttpEntity
    Custom implementation of RequestEntity that delegates to an RepeatableInputStreamRequestEntity, with the one notable difference, that if the underlying InputStream supports being reset, this RequestEntity will report that it is repeatable and will reset the stream on all subsequent attempts to write out the request. TODO : Move this to apache specific package.
    • Field Summary

      • Fields inherited from class org.apache.http.entity.AbstractHttpEntity

        chunked, contentEncoding, contentType, OUTPUT_BUFFER_SIZE
    • Constructor Summary

      Constructors 
      Constructor Description
      RepeatableInputStreamRequestEntity​(Request<?> request)
      Creates a new RepeatableInputStreamRequestEntity using the information from the specified request.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isChunked()  
      boolean isRepeatable()
      Returns true if the underlying InputStream supports marking/reseting or if the underlying InputStreamRequestEntity is repeatable (i.e. its content length has been set to InputStreamRequestEntity#CONTENT_LENGTH_AUTO and therefore its entire contents will be buffered in memory and can be repeated).
      void writeTo​(OutputStream output)
      Resets the underlying InputStream if this isn't the first attempt to write out the request, otherwise simply delegates to InputStreamRequestEntity to write out the data.
      • Methods inherited from class org.apache.http.entity.BasicHttpEntity

        getContent, getContentLength, isStreaming, setContent, setContentLength
      • Methods inherited from class org.apache.http.entity.AbstractHttpEntity

        consumeContent, getContentEncoding, getContentType, setChunked, setContentEncoding, setContentEncoding, setContentType, setContentType, toString
    • Constructor Detail

      • RepeatableInputStreamRequestEntity

        public RepeatableInputStreamRequestEntity​(Request<?> request)
        Creates a new RepeatableInputStreamRequestEntity using the information from the specified request. If the input stream containing the request's contents is repeatable, then this RequestEntity will report as being repeatable.
        Parameters:
        request - The details of the request being written out (content type, content length, and content).
    • Method Detail

      • isChunked

        public boolean isChunked()
        Specified by:
        isChunked in interface org.apache.http.HttpEntity
        Overrides:
        isChunked in class org.apache.http.entity.AbstractHttpEntity
      • isRepeatable

        public boolean isRepeatable()
        Returns true if the underlying InputStream supports marking/reseting or if the underlying InputStreamRequestEntity is repeatable (i.e. its content length has been set to InputStreamRequestEntity#CONTENT_LENGTH_AUTO and therefore its entire contents will be buffered in memory and can be repeated).
        Specified by:
        isRepeatable in interface org.apache.http.HttpEntity
        Overrides:
        isRepeatable in class org.apache.http.entity.BasicHttpEntity
        See Also:
        org.apache.commons.httpclient.methods.RequestEntity#isRepeatable()
      • writeTo

        public void writeTo​(OutputStream output)
                     throws IOException
        Resets the underlying InputStream if this isn't the first attempt to write out the request, otherwise simply delegates to InputStreamRequestEntity to write out the data.

        If an error is encountered the first time we try to write the request entity, we remember the original exception, and report that as the root cause if we continue to encounter errors, rather than masking the original error.

        Specified by:
        writeTo in interface org.apache.http.HttpEntity
        Overrides:
        writeTo in class org.apache.http.entity.BasicHttpEntity
        Throws:
        IOException
        See Also:
        org.apache.commons.httpclient.methods.RequestEntity#writeRequest(java.io.OutputStream)