-
Notifications
You must be signed in to change notification settings - Fork 882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a helper that exposes an async string request provider #183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
private final byte[] bytes; | ||
|
||
private SingleByteArrayAsyncRequestProvider(DefaultBuilder builder) { | ||
this.bytes = builder.bytes.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does clone do for a byte array? Is it a deep copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's just a reference copy, but since byte
is primitive it shouldn't matter.
Builder bytes(byte[] bytes); | ||
} | ||
|
||
public static class DefaultBuilder implements Builder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For internal stuff I think we can skip the builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just following the pattern we used for https://github.com/aws/aws-sdk-java-v2/blob/master/core/src/main/java/software/amazon/awssdk/async/FileAsyncRequestProvider.java
but I'm happy to skip the builder - we can always add it later if we ever want to make this public.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, I made that public since there were some options worth exposing. If we don't expose the class I'd stick with a constructor for now.
} | ||
|
||
|
||
private abstract class SingleSubscriber<T> implements Subscriber<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a SimpleSubscriber you can use to consume the content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schweet!
4cec274
to
4ff4020
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates made
Builder bytes(byte[] bytes); | ||
} | ||
|
||
public static class DefaultBuilder implements Builder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just following the pattern we used for https://github.com/aws/aws-sdk-java-v2/blob/master/core/src/main/java/software/amazon/awssdk/async/FileAsyncRequestProvider.java
but I'm happy to skip the builder - we can always add it later if we ever want to make this public.
private final byte[] bytes; | ||
|
||
private SingleByteArrayAsyncRequestProvider(DefaultBuilder builder) { | ||
this.bytes = builder.bytes.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's just a reference copy, but since byte
is primitive it shouldn't matter.
} | ||
|
||
|
||
private abstract class SingleSubscriber<T> implements Subscriber<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schweet!
… to the AsyncRequestProvider.fromFile implementation.
4ff4020
to
dda996e
Compare
* @see SingleByteArrayAsyncRequestProvider | ||
*/ | ||
static AsyncRequestProvider fromString(String string, Charset cs) { | ||
return new SingleByteArrayAsyncRequestProvider(string.getBytes(cs)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileAsyncRequestProvider in this class uses builder pattern. What about doing same for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See @shorea comments. ;) I
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, his comments were hidden due to a new revision of PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good 😄
Can be used (for example) for uploading to s3: