@@ -120,38 +120,29 @@ public static RequestBody fromFile(File file) {
120
120
* Creates a {@link RequestBody} from an input stream. {@value Header#CONTENT_LENGTH} must
121
121
* be provided so that the SDK does not have to make two passes of the data.
122
122
* <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
125
125
* could tamper with the sending of the request.
126
126
* <p>
127
127
* To support resetting via {@link ContentStreamProvider}, this uses {@link InputStream#reset()} and uses a read limit of
128
128
* 128 KiB. If you need more control, use {@link #fromContentProvider(ContentStreamProvider, long, String)} or
129
129
* {@link #fromContentProvider(ContentStreamProvider, String)}.
130
130
*
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
+ *
131
135
* @param inputStream Input stream to send to the service. The stream will not be closed by the SDK.
132
136
* @param contentLength Content length of data in input stream. If a content length smaller than the actual size of the
133
137
* object is set, the client will truncate the stream to the specified content length and only send
134
138
* exactly the number of bytes equal to the content length.
135
139
* @return RequestBody instance.
136
140
*/
137
141
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 );
155
146
}
156
147
157
148
/**
0 commit comments