@@ -120,38 +120,29 @@ public static RequestBody fromFile(File file) {
120120 * Creates a {@link RequestBody} from an input stream. {@value Header#CONTENT_LENGTH} must
121121 * be provided so that the SDK does not have to make two passes of the data.
122122 * <p>
123- * The stream will not be closed by the SDK. It is up to to caller of this method to close the stream. The stream
124- * should not be read outside of the SDK (by another thread) as it will change the state of the {@link InputStream} and
123+ * The stream will not be closed by the SDK. It is up to caller of this method to close the stream. The stream
124+ * should not be read outside the SDK (by another thread) as it will change the state of the {@link InputStream} and
125125 * could tamper with the sending of the request.
126126 * <p>
127127 * To support resetting via {@link ContentStreamProvider}, this uses {@link InputStream#reset()} and uses a read limit of
128128 * 128 KiB. If you need more control, use {@link #fromContentProvider(ContentStreamProvider, long, String)} or
129129 * {@link #fromContentProvider(ContentStreamProvider, String)}.
130130 *
131+ * <p>
132+ * It is recommended to provide a stream that supports mark and reset for retry. If the stream does not support mark and
133+ * reset, an {@link IllegalStateException} will be thrown during retry.
134+ *
131135 * @param inputStream Input stream to send to the service. The stream will not be closed by the SDK.
132136 * @param contentLength Content length of data in input stream. If a content length smaller than the actual size of the
133137 * object is set, the client will truncate the stream to the specified content length and only send
134138 * exactly the number of bytes equal to the content length.
135139 * @return RequestBody instance.
136140 */
137141 public static RequestBody fromInputStream (InputStream inputStream , long contentLength ) {
138- IoUtils .markStreamWithMaxReadLimit (inputStream );
139- InputStream nonCloseable = nonCloseableInputStream (inputStream );
140- ContentStreamProvider provider = new ContentStreamProvider () {
141- @ Override
142- public InputStream newStream () {
143- if (nonCloseable .markSupported ()) {
144- invokeSafely (nonCloseable ::reset );
145- }
146- return nonCloseable ;
147- }
148-
149- @ Override
150- public String name () {
151- return ProviderType .STREAM .getName ();
152- }
153- };
154- return fromContentProvider (provider , contentLength , Mimetype .MIMETYPE_OCTET_STREAM );
142+ ContentStreamProvider contentStreamProvider = ContentStreamProvider .fromInputStream (
143+ nonCloseableInputStream (inputStream ));
144+ return fromContentProvider (contentStreamProvider ,
145+ contentLength , Mimetype .MIMETYPE_OCTET_STREAM );
155146 }
156147
157148 /**
0 commit comments