Take notice of HTTP response code when downloading icons

This commit is contained in:
Ciaran Gultnieks 2012-09-10 21:00:03 +01:00
parent cc3970cc24
commit 568b615ecf

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.security.cert.Certificate; import java.security.cert.Certificate;
@ -244,20 +245,25 @@ public class RepoXMLHandler extends DefaultHandler {
if (f.exists()) if (f.exists())
return; return;
BufferedInputStream getit = new BufferedInputStream(new URL(mserver URL u = new URL(mserver + "/icons/" + app.icon);
+ "/icons/" + app.icon).openStream()); HttpURLConnection uc = (HttpURLConnection) u.openConnection();
FileOutputStream saveit = new FileOutputStream(destpath); if (uc.getResponseCode() == 200) {
BufferedOutputStream bout = new BufferedOutputStream(saveit, 1024); BufferedInputStream getit = new BufferedInputStream(
byte data[] = new byte[1024]; uc.getInputStream());
FileOutputStream saveit = new FileOutputStream(destpath);
BufferedOutputStream bout = new BufferedOutputStream(saveit,
1024);
byte data[] = new byte[1024];
int readed = getit.read(data, 0, 1024); int readed = getit.read(data, 0, 1024);
while (readed != -1) { while (readed != -1) {
bout.write(data, 0, readed); bout.write(data, 0, readed);
readed = getit.read(data, 0, 1024); readed = getit.read(data, 0, 1024);
}
bout.close();
getit.close();
saveit.close();
} }
bout.close();
getit.close();
saveit.close();
} catch (Exception e) { } catch (Exception e) {
} }