Okio's BufferedSource request() only fires onceHow to log request and response body with Retrofit-Android?Cancel all Retrofit requests at once?How can I perform this request using Retrofit?Retrofit2 request paths not working as expectedrefrofit2 request with filter param. @Query instead of @PathRx Java Retrofit with flatMap runs only onceRetrofit+Okhttp.HTTP 504 Unsatisfiable Request (only-if-cached)Changing request inside Retrofit CallAdapterHow to request multiple Retrofit2 Call and callback once it all requests finished?onPostExecute() seems to be called only once
What is this red bug infesting some trees in southern Germany?
Why do many programmers abstain from using global variables?
What is the significance of 104% for throttle power and rotor speed?
Deleting millions of records on SQL Server 14.0
Would you recommend a keyboard for beginners with or without lights in keys for learning?
Can there be plants on the dark side of a tidally locked world?
What does "se jouer" mean here?
Why would a Intel 8080 chip be destroyed if +12 V is connected before -5 V?
If I have an accident, should I file a claim with my car insurance company?
What's the difference between a share and a stock?
What would a biological creature need in order to see the future?
Does immunity to damage from nonmagical attacks negate a rogue's Sneak Attack damage?
Short story with a first person narrator in a future where racial conflict had exploded into an all out war
Does the Scrying spell require you to have a clear path to the target in order to work?
How to anonymously report the Establishment Clause being broken?
co-son-in-law or co-brother
One hour 10 min layover in Newark; International -> Domestic connection. Enough time to clear customs?
Archiving processor does not archive
Given a specific computer system, is it possible to estimate the actual precise run time of a piece of Assembly code
Case Studies and Real Problems for Teaching Optimization and Modelling
Question about derivation of kinematics equations
If p-value is exactly 1 (1.0000000), what are the confidence interval limits?
How does speed affect lift?
Too many SOQL Queries when inserting records
Okio's BufferedSource request() only fires once
How to log request and response body with Retrofit-Android?Cancel all Retrofit requests at once?How can I perform this request using Retrofit?Retrofit2 request paths not working as expectedrefrofit2 request with filter param. @Query instead of @PathRx Java Retrofit with flatMap runs only onceRetrofit+Okhttp.HTTP 504 Unsatisfiable Request (only-if-cached)Changing request inside Retrofit CallAdapterHow to request multiple Retrofit2 Call and callback once it all requests finished?onPostExecute() seems to be called only once
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm downloading a file using a Retrofit2 implementation of a REST API, per the nice tutorial at https://futurestud.io/tutorials/retrofit-2-how-to-download-files-from-server.
My API interface declares the @GET
as @Streaming
, and indeed when I read from the InputStream
given me by byteStream()
, I can read the entire 29 MB file.
What I'd like to do is read it all in 4 MB chunks, so I'm using Okio's handy BufferedSource
. The problem is that my call to request(4*1024*1024)
returns true
only once, though the total file size is something on the order of 29 MB.
My Java:
@Streaming @GET Call<ResponseBody> get(@Url String url);
// ...
Response<ResponseBody> response = api.get("https://my.file.url");
final int bufSize = 4*1024*1024;
byte[] buffer;
long total;
InputStream is = response.body().byteStream();
BufferedSource ss = Okio.buffer(Okio.source(is));
// Is this the same as ss=response.body().source() ??
while (ss.request(bufSize))
buffer = ss.readByteArray();
total += doSomethingUsefulWith(buffer);
System.out.println("Running total: " + total);
// Capture the < 4MB residue
buffer = ss.readByteArray();
if (buffer.length > 0)
total += doSomethingUsefulWith(buffer);
System.out.println("Total: " + total);
System.out.println("That's all, folks!");
Console output:
Running total: 4194304
That's all, folks!
Again, the raw InputStream
does give me the full 29 MB, I've done it before. Do I misunderstand request()
? What am I doing wrong?
retrofit2 okio
add a comment |
I'm downloading a file using a Retrofit2 implementation of a REST API, per the nice tutorial at https://futurestud.io/tutorials/retrofit-2-how-to-download-files-from-server.
My API interface declares the @GET
as @Streaming
, and indeed when I read from the InputStream
given me by byteStream()
, I can read the entire 29 MB file.
What I'd like to do is read it all in 4 MB chunks, so I'm using Okio's handy BufferedSource
. The problem is that my call to request(4*1024*1024)
returns true
only once, though the total file size is something on the order of 29 MB.
My Java:
@Streaming @GET Call<ResponseBody> get(@Url String url);
// ...
Response<ResponseBody> response = api.get("https://my.file.url");
final int bufSize = 4*1024*1024;
byte[] buffer;
long total;
InputStream is = response.body().byteStream();
BufferedSource ss = Okio.buffer(Okio.source(is));
// Is this the same as ss=response.body().source() ??
while (ss.request(bufSize))
buffer = ss.readByteArray();
total += doSomethingUsefulWith(buffer);
System.out.println("Running total: " + total);
// Capture the < 4MB residue
buffer = ss.readByteArray();
if (buffer.length > 0)
total += doSomethingUsefulWith(buffer);
System.out.println("Total: " + total);
System.out.println("That's all, folks!");
Console output:
Running total: 4194304
That's all, folks!
Again, the raw InputStream
does give me the full 29 MB, I've done it before. Do I misunderstand request()
? What am I doing wrong?
retrofit2 okio
Yes, simplify toss=response.body().source()
– Eric Cochran
Apr 10 at 0:00
also, note thatrequest
will return false at the end, so you'll miss the last 5MB (29-(8+8+8)). not sure if that's what you want.
– Eric Cochran
Apr 10 at 0:03
add a comment |
I'm downloading a file using a Retrofit2 implementation of a REST API, per the nice tutorial at https://futurestud.io/tutorials/retrofit-2-how-to-download-files-from-server.
My API interface declares the @GET
as @Streaming
, and indeed when I read from the InputStream
given me by byteStream()
, I can read the entire 29 MB file.
What I'd like to do is read it all in 4 MB chunks, so I'm using Okio's handy BufferedSource
. The problem is that my call to request(4*1024*1024)
returns true
only once, though the total file size is something on the order of 29 MB.
My Java:
@Streaming @GET Call<ResponseBody> get(@Url String url);
// ...
Response<ResponseBody> response = api.get("https://my.file.url");
final int bufSize = 4*1024*1024;
byte[] buffer;
long total;
InputStream is = response.body().byteStream();
BufferedSource ss = Okio.buffer(Okio.source(is));
// Is this the same as ss=response.body().source() ??
while (ss.request(bufSize))
buffer = ss.readByteArray();
total += doSomethingUsefulWith(buffer);
System.out.println("Running total: " + total);
// Capture the < 4MB residue
buffer = ss.readByteArray();
if (buffer.length > 0)
total += doSomethingUsefulWith(buffer);
System.out.println("Total: " + total);
System.out.println("That's all, folks!");
Console output:
Running total: 4194304
That's all, folks!
Again, the raw InputStream
does give me the full 29 MB, I've done it before. Do I misunderstand request()
? What am I doing wrong?
retrofit2 okio
I'm downloading a file using a Retrofit2 implementation of a REST API, per the nice tutorial at https://futurestud.io/tutorials/retrofit-2-how-to-download-files-from-server.
My API interface declares the @GET
as @Streaming
, and indeed when I read from the InputStream
given me by byteStream()
, I can read the entire 29 MB file.
What I'd like to do is read it all in 4 MB chunks, so I'm using Okio's handy BufferedSource
. The problem is that my call to request(4*1024*1024)
returns true
only once, though the total file size is something on the order of 29 MB.
My Java:
@Streaming @GET Call<ResponseBody> get(@Url String url);
// ...
Response<ResponseBody> response = api.get("https://my.file.url");
final int bufSize = 4*1024*1024;
byte[] buffer;
long total;
InputStream is = response.body().byteStream();
BufferedSource ss = Okio.buffer(Okio.source(is));
// Is this the same as ss=response.body().source() ??
while (ss.request(bufSize))
buffer = ss.readByteArray();
total += doSomethingUsefulWith(buffer);
System.out.println("Running total: " + total);
// Capture the < 4MB residue
buffer = ss.readByteArray();
if (buffer.length > 0)
total += doSomethingUsefulWith(buffer);
System.out.println("Total: " + total);
System.out.println("That's all, folks!");
Console output:
Running total: 4194304
That's all, folks!
Again, the raw InputStream
does give me the full 29 MB, I've done it before. Do I misunderstand request()
? What am I doing wrong?
retrofit2 okio
retrofit2 okio
edited Mar 28 at 2:44
QED
asked Mar 28 at 1:56
QEDQED
8,6244 gold badges39 silver badges75 bronze badges
8,6244 gold badges39 silver badges75 bronze badges
Yes, simplify toss=response.body().source()
– Eric Cochran
Apr 10 at 0:00
also, note thatrequest
will return false at the end, so you'll miss the last 5MB (29-(8+8+8)). not sure if that's what you want.
– Eric Cochran
Apr 10 at 0:03
add a comment |
Yes, simplify toss=response.body().source()
– Eric Cochran
Apr 10 at 0:00
also, note thatrequest
will return false at the end, so you'll miss the last 5MB (29-(8+8+8)). not sure if that's what you want.
– Eric Cochran
Apr 10 at 0:03
Yes, simplify to
ss=response.body().source()
– Eric Cochran
Apr 10 at 0:00
Yes, simplify to
ss=response.body().source()
– Eric Cochran
Apr 10 at 0:00
also, note that
request
will return false at the end, so you'll miss the last 5MB (29-(8+8+8)). not sure if that's what you want.– Eric Cochran
Apr 10 at 0:03
also, note that
request
will return false at the end, so you'll miss the last 5MB (29-(8+8+8)). not sure if that's what you want.– Eric Cochran
Apr 10 at 0:03
add a comment |
1 Answer
1
active
oldest
votes
The call to ss.readByteArray()
will read the entire body into a byte array. Did you mean to do ss.readByteArray(bufSize)
?
Thanks -- I think you may be right here and in your comments. I have since moved on to another solution but I may revisit this later. (Also, I did then have code to handle the last few MB, but good catch.)
– QED
Apr 12 at 18:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389062%2fokios-bufferedsource-request-only-fires-once%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The call to ss.readByteArray()
will read the entire body into a byte array. Did you mean to do ss.readByteArray(bufSize)
?
Thanks -- I think you may be right here and in your comments. I have since moved on to another solution but I may revisit this later. (Also, I did then have code to handle the last few MB, but good catch.)
– QED
Apr 12 at 18:45
add a comment |
The call to ss.readByteArray()
will read the entire body into a byte array. Did you mean to do ss.readByteArray(bufSize)
?
Thanks -- I think you may be right here and in your comments. I have since moved on to another solution but I may revisit this later. (Also, I did then have code to handle the last few MB, but good catch.)
– QED
Apr 12 at 18:45
add a comment |
The call to ss.readByteArray()
will read the entire body into a byte array. Did you mean to do ss.readByteArray(bufSize)
?
The call to ss.readByteArray()
will read the entire body into a byte array. Did you mean to do ss.readByteArray(bufSize)
?
answered Apr 10 at 0:01
Eric CochranEric Cochran
4,9255 gold badges33 silver badges67 bronze badges
4,9255 gold badges33 silver badges67 bronze badges
Thanks -- I think you may be right here and in your comments. I have since moved on to another solution but I may revisit this later. (Also, I did then have code to handle the last few MB, but good catch.)
– QED
Apr 12 at 18:45
add a comment |
Thanks -- I think you may be right here and in your comments. I have since moved on to another solution but I may revisit this later. (Also, I did then have code to handle the last few MB, but good catch.)
– QED
Apr 12 at 18:45
Thanks -- I think you may be right here and in your comments. I have since moved on to another solution but I may revisit this later. (Also, I did then have code to handle the last few MB, but good catch.)
– QED
Apr 12 at 18:45
Thanks -- I think you may be right here and in your comments. I have since moved on to another solution but I may revisit this later. (Also, I did then have code to handle the last few MB, but good catch.)
– QED
Apr 12 at 18:45
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389062%2fokios-bufferedsource-request-only-fires-once%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yes, simplify to
ss=response.body().source()
– Eric Cochran
Apr 10 at 0:00
also, note that
request
will return false at the end, so you'll miss the last 5MB (29-(8+8+8)). not sure if that's what you want.– Eric Cochran
Apr 10 at 0:03