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 ByteArrayContent (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.ByteArrayContent)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.ByteArrayContent)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.ByteArrayContent)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.ByteArrayContent)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.ByteArrayContent)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.ByteArrayContent)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.ByteArrayContent)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.ByteArrayContent) \n\n public final class ByteArrayContent extends AbstractInputStreamContent\n\nConcrete implementation of [AbstractInputStreamContent](/java/docs/reference/google-http-client/latest/com.google.api.client.http.AbstractInputStreamContent) that generates repeatable input\nstreams based on the contents of byte array.\n\nSample use: \n\n \n static void setJsonContent(HttpRequest request, byte[] json) {\n request.setContent(new ByteArrayContent(\"application/json\", json));\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 ByteArrayContent \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\nStatic Methods\n--------------\n\n### fromString(String type, String contentString)\n\n public static ByteArrayContent fromString(String type, String contentString)\n\nReturns a new instance with the UTF-8 encoding (using [StringUtils#getBytesUtf8(String)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.StringUtils#com_google_api_client_util_StringUtils_getBytesUtf8_java_lang_String_))\nof the given content string.\n\nSample use: \n\n \n static void setJsonContent(HttpRequest request, String json) {\n request.setContent(ByteArrayContent.fromString(\"application/json\", json));\n }\n \n \nConstructors\n------------\n\n### ByteArrayContent(String type, byte\\[\\] array)\n\n public ByteArrayContent(String type, byte[] array)\n\nConstructor from byte array content that has already been encoded.\n\n### ByteArrayContent(String type, byte\\[\\] array, int offset, int length)\n\n public ByteArrayContent(String type, byte[] array, int offset, int length)\n\nConstructor from byte array content that has already been encoded, specifying a range of bytes\nto read from the input byte array.\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.ByteArrayContent#com_google_api_client_http_ByteArrayContent_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 ByteArrayContent 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### setType(String type)\n\n public ByteArrayContent 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_)"]]