Reputation: 3230
When downloading a file with HTTPUrlConnection is there a way to check if the server supports resume before attempting to resume a file download?
Either I am doing something wrongor the server doesnt support resume, how can i check first?
File file = new File(Environment.getExternalStorageDirectory()+"/dir/", filename );
if (file.exists()) {
crashes here---> //c.setRequestProperty("Range", "Bytes="+(file.length())+"-");
Log.d("file already exists", filename);
}
c.setDoOutput(true);
c.setDoInput(true);
c.connect();
f = new FileOutputStream(new File(PATH_op), true);//set true so if file exists it will append
LOGCAT
03-17 14:55:23.746: WARN/System.err(11196): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
I found out if the server supports resume and it does, I found this out by checking the Accept-Range reponse as Nuvaak suggested.
Upvotes: 1
Views: 838
Reputation: 12138
I don't think that line would crash your program, if the server does not support the Range
header, it will simply ignore it.
For the question, you may need to issue an extra connection and check the response header Accept-Ranges
, if its value is bytes
, you are lucky that it supports the Range
request header, if it's none
, then don't try it.
Upvotes: 2