# Class InputStreamContent (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.InputStreamContent)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.InputStreamContent)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.InputStreamContent)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.InputStreamContent)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.InputStreamContent)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.InputStreamContent)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.InputStreamContent)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.InputStreamContent)

    public final class InputStreamContent extends AbstractInputStreamContent

Concrete implementation of [AbstractInputStreamContent](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.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](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent).

The input stream is guaranteed to be closed at the end of #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.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [AbstractInputStreamContent](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent) \> InputStreamContent

## Inherited Members

[AbstractInputStreamContent.getCloseInputStream()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getCloseInputStream__) [AbstractInputStreamContent.getInputStream()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getInputStream__) [AbstractInputStreamContent.getType()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getType__) [AbstractInputStreamContent.setCloseInputStream(boolean)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setCloseInputStream_boolean_) [AbstractInputStreamContent.setType(String)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setType_java_lang_String_) [AbstractInputStreamContent.writeTo(OutputStream)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_writeTo_java_io_OutputStream_) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### InputStreamContent(String type, InputStream inputStream)

    public InputStreamContent(String type, InputStream inputStream)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `type` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` Content type or `null` for none |
| `inputStream` | `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` Input stream to read from |

## Methods

### getInputStream()

    public InputStream getInputStream()

Return an input stream for the specific implementation type of [AbstractInputStreamContent](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent). If the specific implementation will return `true` for [#retrySupported()](https://docs.cloud.google.com/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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` |   |

**Overrides** [AbstractInputStreamContent.getInputStream()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_getInputStream__)

### getLength()

    public long getLength()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### retrySupported()

    public boolean retrySupported()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### setCloseInputStream(boolean closeInputStream)

    public InputStreamContent setCloseInputStream(boolean closeInputStream)

Sets whether the input stream should be closed at the end of #writeTo. Default is
`true`. Subclasses should override by calling super.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `closeInputStream` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent` |   |

**Overrides** [AbstractInputStreamContent.setCloseInputStream(boolean closeInputStream)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setCloseInputStream_boolean_)

### setLength(long length)

    public InputStreamContent setLength(long length)

Sets the content length or less than zero if not known.

Defaults to `-1`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `length` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent` |   |

### setRetrySupported(boolean retrySupported)

    public InputStreamContent setRetrySupported(boolean retrySupported)

Sets whether or not retry is supported. Defaults to `false`.

Should be set to `true` if [#getInputStream](https://docs.cloud.google.com/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
position of the input stream.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `retrySupported` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent` |   |

### setType(String type)

    public InputStreamContent setType(String type)

Sets the content type or `null` for none. Subclasses should override by calling super.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `type` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.InputStreamContent` |   |

**Overrides** [AbstractInputStreamContent.setType(String type)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent#com_google_api_client_http_AbstractInputStreamContent_setType_java_lang_String_)