Skip to content
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

Upload progress recipe #8493

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Upload progress recipe #8493

wants to merge 2 commits into from

Conversation

seokjun7410
Copy link

@seokjun7410 seokjun7410 commented Jul 27, 2024

Dear. @swankjesse

I improved the upload progress recipe discussed in #1471 #1528
It was rewritten based on the discussed requirements.

After discussion, I would like to write a Kotlin recipe
I'm awaiting your comments.
Thank you for your time

@yschimke
Copy link
Collaborator

cc @swankjesse @LouisCAD in case you have thoughts, otherwise I'll review next week

@seokjun7410
Copy link
Author

seokjun7410 commented Sep 16, 2024

@yschimke If you officially provide the recipe, it will be very helpful to new users


@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink bufferSink = Okio.buffer(sink(sink));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supernit: bufferedSink, not bufferSink

public void writeTo(BufferedSink sink) throws IOException {
BufferedSink bufferSink = Okio.buffer(sink(sink));
requestBody.writeTo(bufferSink);
bufferSink.close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, the implementation of writeTo() shouldn’t close sink

private static class ProgressRequestBody extends RequestBody {

private final ProgressListener progressListener;
private final RequestBody requestBody;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to delegate ?

@Override
public void close() throws IOException {
super.close();
progressListener.update(totalBytesWritten, contentLength(),true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supernit: formatting. Space after ,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIGHT want to make this only call progressListener.update() once even if close() is called multiple times. You’re allowed to call close() multiple times but listeners shouldn’t be called more than once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants