-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathTinyBufferAsyncRequestBody.java
More file actions
34 lines (27 loc) · 1.14 KB
/
TinyBufferAsyncRequestBody.java
File metadata and controls
34 lines (27 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package software.amazon.encryption.s3.utils;
import org.reactivestreams.Subscriber;
import software.amazon.awssdk.core.async.AsyncRequestBody;
import java.nio.ByteBuffer;
import java.util.Optional;
/**
* AsyncRequestBody which wraps another AsyncRequestBody with a {@link TinyBufferSubscriber}.
* This is useful for testing poor network conditions where buffers may not be larger than
* the cipher's block size.
* DO NOT USE THIS IN PRODUCTION. In addition to degraded performance,
* it will cause IllegalStateExceptions in the base Subscriber as it does not comply
* with the Reactive Streaming spec.
*/
public class TinyBufferAsyncRequestBody implements AsyncRequestBody {
private final AsyncRequestBody wrappedAsyncRequestBody;
public TinyBufferAsyncRequestBody(final AsyncRequestBody wrappedRequestBody) {
wrappedAsyncRequestBody = wrappedRequestBody;
}
@Override
public Optional<Long> contentLength() {
return wrappedAsyncRequestBody.contentLength();
}
@Override
public void subscribe(Subscriber<? super ByteBuffer> s) {
wrappedAsyncRequestBody.subscribe(new TinyBufferSubscriber(s));
}
}