0

I have small piece of code which downloads a zip file from github. I have inserted the token in this format https://token:x-oauth-basic@github.xxxx.com/org/repo/archive/branch.zip. The download works but when I do

ZipInputStream zis = ZipInputStream new FileInputStream(new FileInputStream(downloadedfilepath));
ZipEntry entry = null;
while ((entry=zis.getNextEntry()) != null) {
       System.out.println("Reached"); 
}

zis.getNextEntry() returns null though there is lot of content in the zip. This code works for any other zip but does not work for zips downloaded from github using a token.

Any help would really appricate.

user2124733
  • 51
  • 1
  • 1
  • 4
  • Can you open the zip with any other tools (Winzip or `zip` from the command line)? – rlegendi Oct 13 '14 at 07:42
  • when I download it manually I am able to unzip. But when downloaded using the above method using tokenxxxx I am not able to manually unzip it. The zip turns into a .zip.cpgz which indicates it to be corrupted. This is my Code to download.. URL url = new URL(fileURL); HttpsURLConnection httpsUrl = (HttpsURLConnection) url.openConnection(); httpsUrl.connect(); BufferedInputStream bis = new BufferedInputStream(httpsUrl.getInputStream()); FileOutputStream fos = new FileOutputStream(targetTempFile); – user2124733 Oct 13 '14 at 15:44
  • 1
    Now we got your issue :-) Check this: http://stackoverflow.com/a/16946066/981284 – rlegendi Oct 14 '14 at 06:25
  • Pefect Thanks rlegendi 'code' URL url = new URL(fileURL); URLConnection uc = url.openConnection(); String token = xxx:xxxx"; String authorizationString = "Basic " + Base64.encodeBase64String(token.getBytes()); uc.setRequestProperty ("Authorization", authorizationString); InputStream instream = uc.getInputStream(); FileOutputStream fos = new FileOutputStream(targetTempFile); and add commons-codec dependency. – user2124733 Oct 14 '14 at 07:19

0 Answers0