1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.4.4.1'

This commit is contained in:
gnosygnu
2016-04-24 22:05:38 -04:00
parent ad140a93fe
commit 5ce4ea2a08
103 changed files with 1767 additions and 340 deletions

View File

@@ -1,25 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
public interface Io_zip_mgr {
void Zip_fil(Io_url src_fil, Io_url trg_fil);
byte[] Zip_bry(byte[] src, int bgn, int len);
byte[] Unzip_bry(byte[] src, int bgn, int len);
void Unzip_to_dir(Io_url src_fil, Io_url trg_dir);
void Zip_dir(Io_url src_dir, Io_url trg_fil);
}

View File

@@ -1,120 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import java.io.*;
import java.util.zip.*;
import gplx.core.envs.*;
public class Io_zip_mgr_base implements Io_zip_mgr {
public void Zip_fil(Io_url src_fil, Io_url trg_fil) {
byte[] src_bry = Io_mgr.Instance.LoadFilBry(src_fil);
byte[] trg_bry = Zip_bry(src_bry, 0, src_bry.length);
Io_mgr.Instance.SaveFilBry(trg_fil, trg_bry);
}
public void Zip_dir(Io_url src_dir, Io_url trg_fil) {
try {
byte[] bry = new byte[4096];
FileOutputStream fil_strm = new FileOutputStream(trg_fil.Raw());
ZipOutputStream zip_strm = new ZipOutputStream(fil_strm);
Zip_dir__add_dir(zip_strm, bry, "", src_dir, Zip_dir__get_subs(src_dir));
zip_strm.flush();
zip_strm.close();
} catch(IOException e) {Err_.new_exc(e, "io", "error duing zip", "src", src_dir.Raw(), "trg", trg_fil.Raw());}
}
private void Zip_dir__add_dir(ZipOutputStream zip_strm, byte[] bry, String zip_path, Io_url owner_dir, Io_url[] subs) {
int len = subs.length;
for (int i = 0; i < len; i++) {
Io_url sub = subs[i];
String sub_path = zip_path + sub.NameAndExt_noDirSpr();
if (sub.Type_dir())
Zip_dir__add_dir(zip_strm, bry, sub_path + "/", sub, Zip_dir__get_subs(sub));
else
Zip_dir__add_fil(zip_strm, bry, sub_path, sub);
}
}
private void Zip_dir__add_fil(ZipOutputStream zip_strm, byte[] bry, String zip_path, Io_url fil_url) {
try {
int len;
FileInputStream fil_strm = new FileInputStream(fil_url.Raw());
zip_strm.putNextEntry(new ZipEntry(zip_path));
while ((len = fil_strm.read(bry)) > 0)
zip_strm.write(bry, 0, len);
fil_strm.close();
} catch(IOException e) {throw Err_.new_exc(e, "io", "error duing zip", "src", zip_path);}
}
private Io_url[] Zip_dir__get_subs(Io_url url) {
return Io_mgr.Instance.QueryDir_args(url).DirInclude_().ExecAsUrlAry();
}
public byte[] Zip_bry(byte[] src, int bgn, int len) {
ByteArrayInputStream src_stream = new ByteArrayInputStream(src, bgn, len);
ByteArrayOutputStream trg_stream = new ByteArrayOutputStream(len);
try {
ZipOutputStream trgZip = new ZipOutputStream(trg_stream);
ZipEntry entry = new ZipEntry("file");
trgZip.putNextEntry(entry);
int count;
while((count = src_stream.read(tmp, 0, tmpLen)) != -1) {
trgZip.write(tmp, 0, count);
}
trgZip.close();
} catch(Exception e) {throw Err_.new_wo_type("failed to zip", "err", e.getMessage());}
return trg_stream.toByteArray();
}
public byte[] Unzip_bry(byte[] src, int bgn, int len) {
ByteArrayInputStream src_stream = new ByteArrayInputStream(src, bgn, len);
ByteArrayOutputStream trg_stream = new ByteArrayOutputStream(len);
try {
ZipInputStream srcZip = new ZipInputStream(src_stream);
int count;
while(srcZip.getNextEntry() != null) {
while ((count = srcZip.read(tmp, 0, tmpLen)) != -1) {
trg_stream.write(tmp, 0, count);
}
}
} catch(Exception e) {throw Err_.new_wo_type("failed to unzip", "err", e.getMessage());}
return trg_stream.toByteArray();
}
public void Unzip_to_dir(Io_url src_fil, Io_url trg_dir) {
byte[] buffer = new byte[4096];
try{
Io_mgr.Instance.CreateDirIfAbsent(trg_dir);
ZipInputStream zip_strm = new ZipInputStream(new FileInputStream(src_fil.Raw()));
ZipEntry zip_eny = zip_strm.getNextEntry();
while (zip_eny != null) {
String itm_name = zip_eny.getName();
if (Op_sys.Cur().Tid_is_wnt()) itm_name = String_.Replace(itm_name, "/", "\\");
Io_url itm_url = Io_url_.new_any_(trg_dir.GenSubFil(itm_name).Raw());
Io_mgr.Instance.CreateDirIfAbsent(itm_url.OwnerDir()); // make sure owner dir exists
if (itm_url.Type_fil()) {
Io_mgr.Instance.SaveFilStr_args(itm_url, "").Exec();
File itm_file = new File(itm_url.Raw());
FileOutputStream itm_strm = new FileOutputStream(itm_file);
int len;
while ((len = zip_strm.read(buffer)) > 0)
itm_strm.write(buffer, 0, len);
itm_strm.close();
}
zip_eny = zip_strm.getNextEntry();
}
zip_strm.closeEntry();
zip_strm.close();
} catch(IOException e) {throw Err_.new_exc(e, "io", "error duing unzip", "src", src_fil.Raw(), "trg", trg_dir.Raw());}
}
byte[] tmp = new byte[4096]; int tmpLen = 4096;
public static final Io_zip_mgr Instance = new Io_zip_mgr_base();
}

View File

@@ -1,36 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
public class Io_zip_mgr_mok implements Io_zip_mgr {
public void Zip_fil(Io_url src_fil, Io_url trg_fil) {
byte[] src_bry = Io_mgr.Instance.LoadFilBry(src_fil);
byte[] zip_bry = Zip_bry(src_bry, 0, src_bry.length);
Io_mgr.Instance.SaveFilBry(trg_fil, zip_bry);
}
public void Zip_dir(Io_url src_dir, Io_url trg_fil) {}
public byte[] Zip_bry(byte[] src, int bgn, int len) {return Bry_.Add(Bry_zipped, Bry_.Mid(src, bgn, len));}
public byte[] Unzip_bry(byte[] src, int bgn, int len) {
if (src == Bry_.Empty) return src;
byte[] section = Bry_.Mid(src, bgn, bgn + len);
if (!Bry_.Has_at_bgn(section, Bry_zipped, 0, section.length)) throw Err_.new_wo_type("src not zipped", "section", String_.new_u8(section));
return Bry_.Mid(section, Bry_zipped.length, section.length);
}
public void Unzip_to_dir(Io_url src_fil, Io_url trg_dir) {}
private static final byte[] Bry_zipped = Bry_.new_a7("zipped:");
public static final Io_zip_mgr_mok Instance = new Io_zip_mgr_mok(); Io_zip_mgr_mok() {}
}

View File

@@ -1,31 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.ios; import gplx.*; import gplx.core.*;
import org.junit.*;
public class Io_zip_mgr_tst {
@Test public void Zip_unzip() {
Zip_unzip_tst("abcdefghijklmnopqrstuvwxyz");
}
private void Zip_unzip_tst(String s) {
Io_zip_mgr zip_mgr = Io_zip_mgr_base.Instance;
byte[] src = Bry_.new_a7(s);
byte[] zip = zip_mgr.Zip_bry(src, 0, src.length);
byte[] unz = zip_mgr.Unzip_bry(zip, 0, zip.length);
Tfds.Eq_ary(src, unz);
}
}

View File

@@ -20,5 +20,6 @@ public interface Http_client_rdr {
void Stream_(Object o);
String Read_line();
byte[] Read_line_as_bry();
int Read_char_ary(char[] ary, int bgn, int len);
void Rls();
}

View File

@@ -31,5 +31,6 @@ class Http_client_rdr__mem implements Http_client_rdr {
return idx == ary_len ? null : ary[idx++];
}
public byte[] Read_line_as_bry() {return Bry_.new_u8(Read_line());}
public int Read_char_ary(char[] ary, int bgn, int len) {throw Err_.new_unimplemented();}
public void Rls() {}
}

View File

@@ -26,6 +26,10 @@ class Http_client_rdr__stream implements Http_client_rdr {
try {return br.readLine();}
catch (IOException e) {throw Err_.new_exc(e, "net", "Read_line failed");}
}
public int Read_char_ary(char[] ary, int bgn, int len) {
try {return br.read(ary, bgn, len);}
catch (IOException e) {throw Err_.new_exc(e, "net", "Read_line failed");}
}
public byte[] Read_line_as_bry() {return Bry_.new_u8(Read_line());}
public void Rls() {
try {br.close();}

View File

@@ -22,8 +22,8 @@ public class Http_request_parser {
private int type, content_length;
private byte[] url, protocol, host, user_agent, accept, accept_language, accept_encoding, x_requested_with, cookie, referer, content_type, content_type_boundary, connection, pragma, cache_control, origin;
private Http_post_data_hash post_data_hash;
private final Bry_bfr tmp_bfr = Bry_bfr.new_(255);
private final Http_server_wtr server_wtr; private final boolean log;
private final Bry_bfr tmp_bfr = Bry_bfr.new_(255);
private final Http_server_wtr server_wtr; private final boolean log;
public Http_request_parser(Http_server_wtr server_wtr, boolean log) {this.server_wtr = server_wtr; this.log = log;}
public void Clear() {
this.dnt = false;
@@ -147,7 +147,7 @@ public class Http_request_parser {
private String To_str() {return Make_request_itm().To_str(tmp_bfr, Bool_.N);}
private static final int Tid_get = 1, Tid_post = 2, Tid_host = 3, Tid_user_agent = 4, Tid_accept = 5, Tid_accept_language = 6, Tid_accept_encoding = 7, Tid_dnt = 8
, Tid_x_requested_with = 9, Tid_cookie = 10, Tid_referer = 11, Tid_content_length = 12, Tid_content_type = 13, Tid_connection = 14, Tid_pragma = 15, Tid_cache_control = 16, Tid_origin = 17;
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.ci_a7()
.Add_str_int("GET" , Tid_get)
.Add_str_int("POST" , Tid_post)
.Add_str_int("Host:" , Tid_host)
@@ -166,7 +166,7 @@ public class Http_request_parser {
.Add_str_int("Cache-Control:" , Tid_cache_control)
.Add_str_int("Origin:" , Tid_origin)
;
private static final byte[] Tkn_boundary = Bry_.new_a7("boundary="), Tkn_content_type_boundary_end = Bry_.new_a7("--")
private static final byte[] Tkn_boundary = Bry_.new_a7("boundary="), Tkn_content_type_boundary_end = Bry_.new_a7("--")
, Tkn_content_disposition = Bry_.new_a7("Content-Disposition:"), Tkn_form_data = Bry_.new_a7("form-data;")
, Tkn_name = Bry_.new_a7("name=")
;

View File

@@ -1,44 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.primitives; import gplx.*; import gplx.core.*;
public class Int_list {
private int[] ary = Int_.Ary_empty; private int ary_len, ary_max;
public void Add(int uid) {
int new_len = ary_len + 1;
if (new_len > ary_max) {
ary_max += 16;
int[] new_ary = new int[ary_max];
Int_.Ary_copy_to(ary, ary_len, new_ary);
ary = new_ary;
}
ary[ary_len] = uid;
ary_len = new_len;
}
public int Len() {return ary_len;}
public int Get_at(int i) {return ary[i];}
public void Clear() {
ary = Int_.Ary_empty;
ary_len = ary_max = 0;
}
public static Int_list new_(int... ary) {
Int_list rv = new Int_list();
int len = ary.length;
rv.ary = ary; rv.ary_len = len; rv.ary_max = len;
return rv;
}
}

View File

@@ -18,11 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.tests; import gplx.*; import gplx.core.*;
import gplx.core.brys.*;
public class Gftest {
private static Bry_bfr bfr = Bry_bfr.new_();
private static final Bry_bfr bfr = Bry_bfr.new_();
public static void Eq__ary(String[] expd, byte[][] actl, String msg_fmt, Object... msg_args) {Eq__ary(Bry_.Ary(expd), actl, msg_fmt, msg_args);}
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary) {Eq__ary(expd_ary, actl_ary, null);}
public static void Eq__ary(Bry_bfr_able[] expd_ary, Bry_bfr_able[] actl_ary, String msg_fmt, Object... msg_args) {
byte[][] expd_bry_ary = Bry_bfr_able_.To_bry_ary(bfr, expd_ary);
byte[][] actl_bry_ary = Bry_bfr_able_.To_bry_ary(bfr, actl_ary);
Eq__ary(Bry_bfr_able_.To_bry_ary(bfr, expd_ary), Bry_bfr_able_.To_bry_ary(bfr, actl_ary), msg_fmt, msg_args);
}
public static void Eq__ary(byte[][] expd_bry_ary, byte[][] actl_bry_ary, String msg_fmt, Object... msg_args) {
boolean[] failures = Calc__failures(Type_adp_.Tid__bry, expd_bry_ary, actl_bry_ary);
if (failures != null) {
bfr.Add(Bry__line_bgn);
@@ -40,10 +42,11 @@ public class Gftest {
int actl_len = Array_.Len(actl_ary);
for (int i = 0; i < len; ++i) {
boolean failure = failures[i];
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, 5 - Int_.DigitCount(i), i).Add_byte_colon().Add_byte_space();
int pad_len = 5 - Int_.DigitCount(i);
bfr.Add_int_pad_bgn(Byte_ascii.Num_0, pad_len, i).Add_byte_colon().Add_byte_space();
Write__itm(bfr, type_id, expd_ary, expd_len, i);
if (failure) {
bfr.Add(Bry__item__eq_n).Add_byte_repeat(Byte_ascii.Space, 3);
bfr.Add(Bry__item__eq_n).Add_byte_repeat(Byte_ascii.Space, pad_len - 1);
Write__itm(bfr, type_id, actl_ary, actl_len, i);
}
}