Class InputStreamContent

  • All Implemented Interfaces:
    HttpContent, StreamingContent

    public final class InputStreamContent
    extends AbstractInputStreamContent
    Concrete implementation of AbstractInputStreamContent that simply handles the transfer of data from an input stream to an output stream. This should only be used for streams that can not be re-opened and retried. If you have a stream that it is possible to recreate please create a new subclass of AbstractInputStreamContent.

    The input stream is guaranteed to be closed at the end of AbstractInputStreamContent.writeTo(OutputStream).

    Sample use with a URL:

     
     private static void setRequestJpegContent(HttpRequest request, URL jpegUrl) throws IOException {
     request.setContent(new InputStreamContent("image/jpeg", jpegUrl.openStream()));
     }
     
     

    Implementation is not thread-safe.

    Since:
    1.0
    • Field Detail

      • length

        private long length
        Content length or less than zero if not known. Defaults to -1.
      • retrySupported

        private boolean retrySupported
        Whether or not retry is supported. Defaults to false.
      • inputStream

        private final java.io.InputStream inputStream
        Input stream to read from.
    • Constructor Detail

      • InputStreamContent

        public InputStreamContent​(java.lang.String type,
                                  java.io.InputStream inputStream)
        Parameters:
        type - Content type or null for none
        inputStream - Input stream to read from
        Since:
        1.5