-
Notifications
You must be signed in to change notification settings - Fork 841
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
Add Progress Callback #47
Conversation
@@ -2527,8 +2543,14 @@ protected HttpRequest copy(final InputStream input, final OutputStream output) | |||
public HttpRequest run() throws IOException { | |||
final byte[] buffer = new byte[bufferSize]; | |||
int read; | |||
while ((read = input.read(buffer)) != -1) | |||
int totalWritten = 0; |
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.
Maybe this should be initialised at the same place where totalSize
is initialised. In case people upload multiple files using part()
, totalSize
would grow, but totalWritten
would be reset all the time.
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.
Initializing this where totalSize
is seems like a good idea.
Friendly ping. |
Thanks for the ping, sorry for the delay, will take a look soon. |
Sorry again for the delay in reviewing this. Looks good and I'm down for merging it once we have a unit test for it. |
I'll add the same code for downloading and a test for both in the coming days (will probably a week anyway). In the meantime, how (if at all) should we address the problem with the possible Also what about the line note I added? Should I address this issue or should I leave it as a known "limitation". |
output.write(buffer, 0, read); | ||
if (progress != null) { |
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.
Instead of checking null every time how about instead we just have a NULL_PROGRESS_CALLBACK
no-op implentation that is private static final and is assigned to progress
when progress()
is called with null callback?
I now modified the second The only thing I'm not sure of is whether -1 is a good idea, since for the other |
public HttpRequest progress(final ProgressCallback callback) { | ||
if (callback != null) { | ||
progress = callback; | ||
} |
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.
If callback
is null it should set progress
back to NULL_PROGRESS_CALLBACK
or else you won't be able to clear a previously registered callback.
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.
Good point.
Will squash when you tell me everything is ready and good to go so until then it's easier for you to review my changes. |
Yeah, I feel like the progress callback should never report So how about just not calling the callback at all if nothing is actually written in either case? |
Well, it might be correct output for the written bytes if we send something empty, no? The problem with the total size being 0 in some cases is that the first |
For the |
That would work for methods like That said, maybe |
|
Heh, I completely missed the |
I want this into http request! Is there any ETA? |
@aried3r is this ready? If it is I'll merge it in and cut a new release, also if you get a chance to add an example to the README.md that would be awesome, or we can do it after merging. |
Sorry, not yet. I want to add further tests for more likely cases. IIRC, there can still be |
@aried3r Yeah, I think |
I merged it in with a few tweaks:
Thanks again for your work on this, let me know if you have any feedback on my tweaks. |
May a few subsequent changes after thinking about it a bit more:
|
Would appreciate any feedback you have if something feels weird. |
Just pushed a 5.6 version with this in it to maven central. |
Hello, is there any need for calling progress(null); in closeOutput() method? Because if you don't then onUpload can be used also for download, only with that you don't get total size, which is ok I suppose. |
This is a work in progress. Implements #28.
For now, it only works for uploading, not for downloading. I'll add the same functionality for it later, but first I'd like to have some feedback, there's a few things I'd love your input on.
File
objects, notStrings
or others.copy()
is not only called when uploading something, but also when getting the request body after the request usingbody()
. This results in output like below. How would you suggest to work around this? I'm a bit reluctant to add a boolean flag to thecopy()
call.