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
    Author:
    Yaniv Inbar