|
38 | 38 | import software.amazon.awssdk.http.ContentStreamProvider; |
39 | 39 | import software.amazon.awssdk.http.Header; |
40 | 40 | import software.amazon.awssdk.utils.BinaryUtils; |
41 | | -import software.amazon.awssdk.utils.IoUtils; |
42 | 41 |
|
43 | 42 | /** |
44 | 43 | * Represents the body of an HTTP request. Must be provided for operations that have a streaming input. |
@@ -120,38 +119,29 @@ public static RequestBody fromFile(File file) { |
120 | 119 | * Creates a {@link RequestBody} from an input stream. {@value Header#CONTENT_LENGTH} must |
121 | 120 | * be provided so that the SDK does not have to make two passes of the data. |
122 | 121 | * <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 |
| 122 | + * The stream will not be closed by the SDK. It is up to caller of this method to close the stream. The stream |
| 123 | + * should not be read outside the SDK (by another thread) as it will change the state of the {@link InputStream} and |
125 | 124 | * could tamper with the sending of the request. |
126 | 125 | * <p> |
127 | 126 | * To support resetting via {@link ContentStreamProvider}, this uses {@link InputStream#reset()} and uses a read limit of |
128 | 127 | * 128 KiB. If you need more control, use {@link #fromContentProvider(ContentStreamProvider, long, String)} or |
129 | 128 | * {@link #fromContentProvider(ContentStreamProvider, String)}. |
130 | 129 | * |
| 130 | + * <p> |
| 131 | + * It is recommended to provide a stream that supports mark and reset for retry. If the stream does not support mark and |
| 132 | + * reset, an {@link IllegalStateException} will be thrown during retry. |
| 133 | + * |
131 | 134 | * @param inputStream Input stream to send to the service. The stream will not be closed by the SDK. |
132 | 135 | * @param contentLength Content length of data in input stream. If a content length smaller than the actual size of the |
133 | 136 | * object is set, the client will truncate the stream to the specified content length and only send |
134 | 137 | * exactly the number of bytes equal to the content length. |
135 | 138 | * @return RequestBody instance. |
136 | 139 | */ |
137 | 140 | 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); |
| 141 | + ContentStreamProvider contentStreamProvider = ContentStreamProvider.fromInputStream( |
| 142 | + nonCloseableInputStream(inputStream)); |
| 143 | + return fromContentProvider(contentStreamProvider, |
| 144 | + contentLength, Mimetype.MIMETYPE_OCTET_STREAM); |
155 | 145 | } |
156 | 146 |
|
157 | 147 | /** |
|
0 commit comments