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

Infinite cycle with MediaHttpDownloader setContentRange download #1101

Closed
sbespalko opened this issue Mar 28, 2018 · 4 comments
Closed

Infinite cycle with MediaHttpDownloader setContentRange download #1101

sbespalko opened this issue Mar 28, 2018 · 4 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@sbespalko
Copy link

When trying to

downloader.setContentRange(0, fileSize / 2);
downloader.download();

The process never ends, because of
mediaContentLength always is maximum content Range and expression:
if( mediaContentLength <= nextByteIndex ) { ... return; }
never give true

@sbespalko sbespalko changed the title Infinite cicle with MediaHttpDownloader setContentRange download Infinite cycle with MediaHttpDownloader setContentRange download Mar 28, 2018
@mattwhisenhunt mattwhisenhunt added the type: question Request for information or clarification. Not an issue. label Mar 28, 2018
@mattwhisenhunt
Copy link
Contributor

Thank you for filing this issue.
Are you building from source or using a release/snapshot? Is this bug related to this commit I merged recently?

@mattwhisenhunt mattwhisenhunt added status: investigating and removed type: question Request for information or clarification. Not an issue. labels Apr 5, 2018
@sbespalko
Copy link
Author

I use release 1.23.0
To understand the problem, please, look the test code:

  @Test
  public void downloadPartialNeverEnds() throws IOException {
    MediaHttpDownloader downloader = new MediaHttpDownloader(new NetHttpTransport(), null);
    downloader.setContentRange(0, 1024);
    OutputStream out = new FileOutputStream(new File("test-file1"));
    downloader.download(new GenericUrl("http://speedtest.ftp.otenet.gr/files/test100k.db"), out);
  }

This method never ends. But expected, that it will download only 1kb.

@JustinBeckwith JustinBeckwith added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. triage me I really want to be triaged. 🚨 This issue needs some love. and removed status: investigating labels Jun 7, 2018
@mattwhisenhunt mattwhisenhunt self-assigned this Jun 25, 2018
@mattwhisenhunt mattwhisenhunt added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. labels Jun 25, 2018
@JustinBeckwith JustinBeckwith removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Jun 25, 2018
@alvazai
Copy link

alvazai commented Aug 25, 2018

I have exactly the same problem. I started palying with Google Drive JAVA API and everything is quite satisfactory so far with the exception of this problem. I understand that the same goal (partial file download) can be achieved by using lower level HTTP requests but I am unfamiliar with HTTP.

Here is my code:

public byte[] downloadPartial(String googleID, long start, long size) throws GoogleDriveClientException{
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Drive.Files.Get get = driveService.files().get(googleID);
MediaHttpDownloader downloader = get.getMediaHttpDownloader();
downloader.setContentRange(start, start+size-1);
get.executeMediaAndDownloadTo(bos);
return bos.toByteArray();
} catch (IOException ex) {
Logger.getLogger(GoogleDriveProxy.class.getName()).log(Level.SEVERE, null, ex);
throw new GoogleDriveClientException("Failure downloading file: " + ex.getMessage());
}
}

If I comment the line
downloader.setContentRange(start, start+size-1);
everything works but of course the whole file content is downloaded

@alvazai
Copy link

alvazai commented Aug 26, 2018

So basically I am asking for help. Can anybody suggest few lines of Java code to set the Content Range in some other way, before I take great pains to understand HTTP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants