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 #writeTo(OutputStream).
Return an input stream for the specific implementation type of AbstractInputStreamContent. If the specific implementation will return true for #retrySupported() this should be a factory function which will create a new InputStream from the source data whenever invoked.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class InputStreamContent (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.InputStreamContent)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.InputStreamContent)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.InputStreamContent)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.InputStreamContent)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.InputStreamContent)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.InputStreamContent)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.InputStreamContent) \n\n public final class InputStreamContent extends AbstractInputStreamContent\n\nConcrete implementation of [AbstractInputStreamContent](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent) that simply handles the transfer of\ndata from an input stream to an output stream. This should only be used for streams that can not\nbe re-opened and retried. If you have a stream that it is possible to recreate please create a\nnew subclass of [AbstractInputStreamContent](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent).\n\nThe input stream is guaranteed to be closed at the end of #writeTo(OutputStream).\n\nSample use with a URL: \n\n \n private static void setRequestJpegContent(HttpRequest request, URL jpegUrl) throws IOException {\n request.setContent(new InputStreamContent(\"image/jpeg\", jpegUrl.openStream()));\n }\n \n \nImplementation is not thread-safe. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e [AbstractInputStreamContent](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent) \\\u003e InputStreamContent \n\nInherited Members\n-----------------\n\n[AbstractInputStreamContent.getCloseInputStream()](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getCloseInputStream__) \n[AbstractInputStreamContent.getInputStream()](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getInputStream__) \n[AbstractInputStreamContent.getType()](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getType__) \n[AbstractInputStreamContent.setCloseInputStream(boolean)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setCloseInputStream_boolean_) \n[AbstractInputStreamContent.setType(String)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setType_java_lang_String_) \n[AbstractInputStreamContent.writeTo(OutputStream)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_writeTo_java_io_OutputStream_) \n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nConstructors\n------------\n\n### InputStreamContent(String type, InputStream inputStream)\n\n public InputStreamContent(String type, InputStream inputStream)\n\nMethods\n-------\n\n### getInputStream()\n\n public InputStream getInputStream()\n\nReturn an input stream for the specific implementation type of [AbstractInputStreamContent](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent). If the specific implementation will return `true` for [#retrySupported()](/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent#com_google_api_client_http_InputStreamContent_retrySupported__) this should be a factory function which will create a new [InputStream](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html) from the source data whenever invoked.\n\n**Overrides** \n[AbstractInputStreamContent.getInputStream()](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getInputStream__)\n\n### getLength()\n\n public long getLength()\n\n### retrySupported()\n\n public boolean retrySupported()\n\n### setCloseInputStream(boolean closeInputStream)\n\n public InputStreamContent setCloseInputStream(boolean closeInputStream)\n\nSets whether the input stream should be closed at the end of #writeTo. Default is\n`true`. Subclasses should override by calling super.\n\n**Overrides** \n[AbstractInputStreamContent.setCloseInputStream(boolean closeInputStream)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setCloseInputStream_boolean_)\n\n### setLength(long length)\n\n public InputStreamContent setLength(long length)\n\nSets the content length or less than zero if not known.\n\nDefaults to `-1`.\n\n### setRetrySupported(boolean retrySupported)\n\n public InputStreamContent setRetrySupported(boolean retrySupported)\n\nSets whether or not retry is supported. Defaults to `false`.\n\nShould be set to `true` if [#getInputStream](/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent#com_google_api_client_http_InputStreamContent_getInputStream_) is called to reset to the original\nposition of the input stream.\n\n### setType(String type)\n\n public InputStreamContent setType(String type)\n\nSets the content type or `null` for none. Subclasses should override by calling super.\n\n**Overrides** \n[AbstractInputStreamContent.setType(String type)](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setType_java_lang_String_)"]]