mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.9.2.1'
This commit is contained in:
@@ -21,6 +21,7 @@ public class Hash_adp__int {
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
private final Int_obj_ref tmp_key = Int_obj_ref.New_neg1();
|
||||
public void Clear() {hash.Clear();}
|
||||
public int Len() {return hash.Count();}
|
||||
public Object Get_by(int key) {return hash.Get_by_or_fail(tmp_key.Val_(key));}
|
||||
public Object Get_by_or_null(int key) {return hash.Get_by(tmp_key.Val_(key));}
|
||||
public void Add(int key, Object obj) {hash.Add(Int_obj_ref.New(key), obj);}
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.core.net.downloads; import gplx.*; import gplx.core.*; import gplx.core.net.*;
|
||||
public interface Http_download_wkr {
|
||||
String Fail_msg();
|
||||
Io_url Tmp_url();
|
||||
Http_download_wkr Make_new();
|
||||
long Checkpoint__load_by_trg_fil(Io_url trg_url);
|
||||
byte Exec(gplx.core.progs.Gfo_prog_ui prog_ui, String src_str, Io_url trg_url, long expd_size);
|
||||
|
||||
@@ -22,6 +22,7 @@ public abstract class Http_download_wkr__base implements Http_download_wkr {
|
||||
private Io_url tmp_url, checkpoint_url;
|
||||
private long downloaded;
|
||||
private long checkpoint_interval = 1024 * 1024, checkpoint_nxt = 0;
|
||||
public Io_url Tmp_url() {return tmp_url;}
|
||||
public String Fail_msg() {return fail_msg;} private String fail_msg;
|
||||
public abstract Http_download_wkr Make_new();
|
||||
public byte Exec(gplx.core.progs.Gfo_prog_ui prog_ui, String src_str, Io_url trg_url, long expd_size_val) {
|
||||
@@ -30,7 +31,12 @@ public abstract class Http_download_wkr__base implements Http_download_wkr {
|
||||
this.expd_size = expd_size_val;
|
||||
this.fail_msg = null;
|
||||
|
||||
byte status = this.Exec_hook(prog_ui, src_str, tmp_url, downloaded);
|
||||
byte status = Gfo_prog_ui_.Status__fail;
|
||||
try {status = this.Exec_hook(prog_ui, src_str, tmp_url, downloaded);}
|
||||
catch (Exception e) {
|
||||
status = Gfo_prog_ui_.Status__fail;
|
||||
fail_msg = Err_.Message_lang(e);
|
||||
}
|
||||
switch (status) {
|
||||
case Gfo_prog_ui_.Status__done: {
|
||||
if (expd_size_val != -1) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
|
||||
URL src_url_itm = null;
|
||||
try {src_url_itm = new URL(src_url);}
|
||||
catch (MalformedURLException e) {
|
||||
try {trg_stream.close();}
|
||||
try {if (trg_stream != null) trg_stream.close();}
|
||||
catch (IOException e1) {}
|
||||
throw Err_.new_("download_file", "bad url", "src", src_url, "err" + e.toString());
|
||||
}
|
||||
@@ -49,26 +49,29 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
|
||||
src_conn = (HttpURLConnection)src_url_itm.openConnection();
|
||||
if (prog_resumed)
|
||||
src_conn.addRequestProperty("Range", "bytes=" + Long_.To_str(prog_data_cur) + "-");
|
||||
src_conn.setReadTimeout(10000); // explicitly set timeout; NOTE:needed on Mac OS X, else error never thrown; DATE:2016-09-03
|
||||
src_conn.connect();
|
||||
|
||||
// check response code
|
||||
int response_code = src_conn.getResponseCode();
|
||||
if (prog_resumed) {
|
||||
if (response_code != HttpURLConnection.HTTP_PARTIAL) {
|
||||
try {trg_stream.close();}
|
||||
try {if (trg_stream != null) trg_stream.close();}
|
||||
catch (IOException e1) {}
|
||||
throw Err_.new_("download_file", "server returned non-partial response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (response_code != HttpURLConnection.HTTP_OK) {
|
||||
try {trg_stream.close();}
|
||||
try {if (trg_stream != null) trg_stream.close();}
|
||||
catch (IOException e1) {}
|
||||
throw Err_.new_("download_file", "server returned non-OK response code", "src", src_url, "code", src_conn.getResponseCode(), "msg", src_conn.getResponseMessage());
|
||||
}
|
||||
}
|
||||
src_stream = src_conn.getInputStream();
|
||||
} catch (Exception e) {
|
||||
try {if (trg_stream != null) trg_stream.close();}
|
||||
catch (IOException e1) {}
|
||||
throw Err_.new_("download_file", "src connection failed", "src", src_url, "err",e.toString());
|
||||
}
|
||||
|
||||
@@ -77,8 +80,9 @@ public class Http_download_wkr__jre extends Http_download_wkr__base {
|
||||
long prog_data_end = prog_ui.Prog_data_end();
|
||||
if (prog_data_end == -1) prog_data_end = src_conn.getContentLength(); // NOTE: may be -1 if server does not report the length
|
||||
byte data[] = new byte[4096];
|
||||
int read = 0;
|
||||
while ((read = src_stream.read(data)) != -1) {
|
||||
while (true) {
|
||||
int read = src_stream.read(data);
|
||||
if (read == -1) break; // no more data
|
||||
prog_data_cur += read;
|
||||
trg_stream.write(data, 0, read);
|
||||
this.Checkpoint__save(prog_data_cur);
|
||||
|
||||
Reference in New Issue
Block a user