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:
@@ -572,6 +572,55 @@ public class Bry_bfr {
|
||||
bfr = null;
|
||||
this.Mkr_rls();
|
||||
}
|
||||
public byte[][] To_bry_ary_and_clear() {
|
||||
if (bfr_len == 0) return Bry_.Ary_empty;
|
||||
Int_list line_ends = Find_all(Byte_ascii.Nl);
|
||||
|
||||
// create lines
|
||||
int lines_len = line_ends.Len();
|
||||
byte[][] rv = new byte[lines_len][];
|
||||
int line_bgn = 0;
|
||||
for (int i = 0; i < lines_len; ++i) {
|
||||
int line_end = line_ends.Get_at(i);
|
||||
rv[i] = Bry_.Mid(bfr, line_bgn, line_end);
|
||||
line_bgn = line_end + 1;
|
||||
}
|
||||
this.ClearAndReset();
|
||||
return rv;
|
||||
}
|
||||
public String[] To_str_ary_and_clear() {
|
||||
if (bfr_len == 0) return String_.Ary_empty;
|
||||
Int_list line_ends = Find_all(Byte_ascii.Nl);
|
||||
|
||||
// create lines
|
||||
int lines_len = line_ends.Len();
|
||||
String[] rv = new String[lines_len];
|
||||
int line_bgn = 0;
|
||||
for (int i = 0; i < lines_len; ++i) {
|
||||
int line_end = line_ends.Get_at(i);
|
||||
rv[i] = String_.new_u8(bfr, line_bgn, line_end);
|
||||
line_bgn = line_end + 1;
|
||||
}
|
||||
this.ClearAndReset();
|
||||
return rv;
|
||||
}
|
||||
private Int_list Find_all(byte find) {
|
||||
Int_list rv = new Int_list();
|
||||
// scan bfr for nl
|
||||
int line_bgn = 0, line_end = 0;
|
||||
while (line_bgn < bfr_len) {
|
||||
line_end = Bry_find_.Find_fwd(bfr, find, line_bgn, bfr_len);
|
||||
if (line_end == Bry_find_.Not_found) { // no more \n; add bfr_end
|
||||
rv.Add(bfr_len);
|
||||
break;
|
||||
}
|
||||
else { // \n found; add it
|
||||
rv.Add(line_end);
|
||||
line_bgn = line_end + 1;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@Override public int hashCode() {return Bry_obj_ref.CalcHashCode(bfr, 0, bfr_len);}
|
||||
@Override public boolean equals(Object obj) {
|
||||
if (obj == null) return false; // NOTE: strange, but null check needed; throws null error; EX.WP: File:Eug<75>ne Delacroix - La libert<72> guidant le peuple.jpg
|
||||
|
||||
@@ -208,9 +208,15 @@ public class Bry_bfr_tst {
|
||||
@Test public void Delete_rng_to_end() {
|
||||
fxt.Test_Delete_rng_to_end("abcd", 2 , "ab");
|
||||
}
|
||||
@Test public void To_bry_ary_and_clear() {
|
||||
fxt.Test__to_bry_ary_and_clear("" ); // empty
|
||||
fxt.Test__to_bry_ary_and_clear("a" , "a"); // lines=1
|
||||
fxt.Test__to_bry_ary_and_clear("a\nb\nc" , "a", "b", "c"); // lines=n
|
||||
fxt.Test__to_bry_ary_and_clear("a\n" , "a"); // nl at end
|
||||
}
|
||||
}
|
||||
class ByteAryBfr_fxt {
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(16);
|
||||
private final Bry_bfr bfr = Bry_bfr.reset_(16);
|
||||
public void Clear() {
|
||||
bfr.ClearAndReset();
|
||||
}
|
||||
@@ -224,4 +230,7 @@ class ByteAryBfr_fxt {
|
||||
public void Test_Delete_rng(String init, int bgn, int end, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng(bgn, end).To_str_and_clear());}
|
||||
public void Test_Delete_rng_to_bgn(String init, int pos, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng_to_bgn(pos).To_str_and_clear());}
|
||||
public void Test_Delete_rng_to_end(String init, int pos, String expd) {Tfds.Eq(expd, bfr.Add_str_u8(init).Delete_rng_to_end(pos).To_str_and_clear());}
|
||||
public void Test__to_bry_ary_and_clear(String bfr_str, String... expd) {
|
||||
Tfds.Eq_ary(expd, String_.Ary(bfr.Add_str_u8(bfr_str).To_bry_ary_and_clear()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
|
||||
public int Match_pos() {return match_pos;} private int match_pos;
|
||||
public Object Match_exact(byte[] src) {return src == null ? null : Match_exact(src, 0, src.length);}
|
||||
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
|
||||
if (bgn_pos == end_pos) return null; // NOTE:handle empty String; DATE:2016-04-21
|
||||
Object rv = Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);
|
||||
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
|
||||
}
|
||||
|
||||
21
100_core/src/gplx/core/ios/zips/Io_zip_decompress_cmd.java
Normal file
21
100_core/src/gplx/core/ios/zips/Io_zip_decompress_cmd.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
public interface Io_zip_decompress_cmd {
|
||||
void Decompress__exec(Io_zip_decompress_task task, Io_url src_fil, Io_url trg_dir);
|
||||
}
|
||||
21
100_core/src/gplx/core/ios/zips/Io_zip_decompress_cmd_.java
Normal file
21
100_core/src/gplx/core/ios/zips/Io_zip_decompress_cmd_.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
public class Io_zip_decompress_cmd_ {
|
||||
public static Io_zip_decompress_cmd New__jre() {return new Io_zip_decompress_cmd__jre();}
|
||||
}
|
||||
103
100_core/src/gplx/core/ios/zips/Io_zip_decompress_cmd__jre.java
Normal file
103
100_core/src/gplx/core/ios/zips/Io_zip_decompress_cmd__jre.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
import gplx.core.envs.*; import gplx.core.threads.*;
|
||||
class Io_zip_decompress_cmd__jre implements Io_zip_decompress_cmd {
|
||||
public void Decompress__exec(Io_zip_decompress_task task, Io_url src_fil, Io_url trg_dir) {
|
||||
// init
|
||||
byte[] buffer = new byte[4096];
|
||||
String resume_entry_name = task.Resume__entry();
|
||||
long resume_bytes = task.Resume__bytes();
|
||||
|
||||
// assert that trg_dir exists and can be written
|
||||
Io_mgr.Instance.CreateDirIfAbsent(trg_dir);
|
||||
|
||||
// open src_fil_stream
|
||||
FileInputStream src_fil_stream = null;
|
||||
try {src_fil_stream = new FileInputStream(src_fil.Raw());}
|
||||
catch (FileNotFoundException e) {throw Err_.new_("ios.zip", "file not found", "path", src_fil.Raw());}
|
||||
|
||||
ZipInputStream src_zip_stream = new ZipInputStream(src_fil_stream);
|
||||
try {
|
||||
ZipEntry entry = null;
|
||||
boolean loop_entries = true;
|
||||
while (loop_entries) {
|
||||
|
||||
// read next entry
|
||||
entry = src_zip_stream.getNextEntry();
|
||||
if ( entry == null // no more entries
|
||||
|| resume_entry_name == null // resume_entry_name will be null in most cases
|
||||
|| String_.Eq(resume_entry_name, entry.getName()) // if resume_entry_name is not null, keep reading until match
|
||||
)
|
||||
break;
|
||||
if (resume_bytes > 0) {
|
||||
src_zip_stream.skip(resume_bytes);
|
||||
resume_bytes = 0;
|
||||
}
|
||||
|
||||
// get entry name; also convert / to \ for wnt
|
||||
String entry_name = entry.getName();
|
||||
task.Prog__update_name(entry_name);
|
||||
if (Op_sys.Cur().Tid_is_wnt()) entry_name = String_.Replace(entry_name, "/", "\\");
|
||||
|
||||
// create file
|
||||
Io_url trg_fil_url = Io_url_.new_any_(trg_dir.GenSubFil(entry_name).Raw());
|
||||
Io_mgr.Instance.CreateDirIfAbsent(trg_fil_url.OwnerDir()); // make sure owner dir exists
|
||||
if (trg_fil_url.Type_fil()) {
|
||||
// write file
|
||||
Io_mgr.Instance.SaveFilStr_args(trg_fil_url, "").Exec(); // need to write to create dirs; permissions;
|
||||
FileOutputStream trg_fil_stream = new FileOutputStream(new File(trg_fil_url.Raw()));
|
||||
boolean loop_bytes = true;
|
||||
while (loop_bytes) {
|
||||
int len = src_zip_stream.read(buffer); if (len < 1) break;
|
||||
trg_fil_stream.write(buffer, 0, len);
|
||||
switch (task.Prog__update(len)) {
|
||||
case Io_zip_decompress_task.Status__canceled:
|
||||
loop_entries = false;
|
||||
loop_bytes = false;
|
||||
break;
|
||||
case Io_zip_decompress_task.Status__paused:
|
||||
while (true) {
|
||||
Thread_adp_.Sleep(1000);
|
||||
if (!task.Paused()) break;
|
||||
if (task.Canceled()) {
|
||||
loop_entries = false;
|
||||
loop_bytes = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Io_zip_decompress_task.Status__ok:
|
||||
break;
|
||||
}
|
||||
}
|
||||
trg_fil_stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException e) {throw Err_.new_exc(e, "ios.zip", "error duing unzip", "src", src_fil.Raw(), "trg", trg_dir.Raw());}
|
||||
finally {
|
||||
try {
|
||||
src_zip_stream.closeEntry();
|
||||
src_zip_stream.close();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
138
100_core/src/gplx/core/ios/zips/Io_zip_decompress_task.java
Normal file
138
100_core/src/gplx/core/ios/zips/Io_zip_decompress_task.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
import gplx.core.threads.*; import gplx.core.progs.*;
|
||||
public class Io_zip_decompress_task implements GfoInvkAble {
|
||||
private Gfo_prog_ui prog_ui;
|
||||
private Io_url src_fil, trg_dir;
|
||||
private boolean async;
|
||||
private boolean canceled, paused;
|
||||
private long src_fil_len = 0;
|
||||
private long prog__cur = 0;
|
||||
private Io_zip_decompress_cmd cmd;
|
||||
public Gfo_prog_task Prog__owner() {return Gfo_prog_task_.Null;}
|
||||
public void Init(boolean async, Gfo_prog_ui prog_ui, Io_zip_decompress_cmd cmd, Io_url src_fil, Io_url trg_dir) {
|
||||
this.async = async; this.cmd = cmd; this.prog_ui = prog_ui;
|
||||
this.src_fil = src_fil; this.trg_dir = trg_dir;
|
||||
}
|
||||
public String Resume__entry() {return resume__entry;} private String resume__entry;
|
||||
public long Resume__bytes() {return resume__bytes;} private long resume__bytes;
|
||||
public boolean Canceled() {return canceled;}
|
||||
public boolean Paused() {return paused;}
|
||||
public void Prog__start() {
|
||||
this.src_fil_len = Io_mgr.Instance.QueryFil(src_fil).Size();
|
||||
this.resume__entry = null;
|
||||
this.resume__bytes = 0;
|
||||
// load resume
|
||||
// prog_ui.Prog__init(src_fil_len);
|
||||
Thread_adp_.Run_cmd(async, "zip.decompress:" + src_fil.Raw(), this, Invk__unzip);
|
||||
}
|
||||
public byte Prog__update(long v) {
|
||||
prog__cur += v;
|
||||
prog_ui.Prog__update_val(prog__cur, src_fil_len);
|
||||
if (paused) return Status__paused;
|
||||
else if (canceled) return Status__canceled;
|
||||
else return Status__ok;
|
||||
}
|
||||
public boolean Prog__update_name(String name) {
|
||||
// prog_ui.Prog__update_misc("name", name);
|
||||
return canceled;
|
||||
}
|
||||
public void Prog__pause() {
|
||||
paused = true;
|
||||
// save resume
|
||||
}
|
||||
public void Prog__resume() {
|
||||
paused = false;
|
||||
}
|
||||
public void Prog__cancel() {
|
||||
canceled = true;
|
||||
// discard resume
|
||||
}
|
||||
public void Unzip() {
|
||||
cmd.Decompress__exec(this, src_fil, trg_dir);
|
||||
prog_ui.Prog__end();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk__unzip)) this.Unzip();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk__unzip = "unzip";
|
||||
public static final byte Status__ok = 0, Status__paused = 1, Status__canceled = 2;
|
||||
}
|
||||
/*
|
||||
class Notifier {
|
||||
public Prog_update_bgn() {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
public Prog_update_end() {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
public Prog_update_val(long cur, long all) {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
public Prog_update_name(String name) {
|
||||
for(Object o : list)
|
||||
o.Prog_update_bgn();
|
||||
}
|
||||
}
|
||||
class unzip_prog_bar {
|
||||
public Prog_update_val(long itm_cur, long itm_all) {
|
||||
cur += itm_cur;
|
||||
double pct = (cur / all) * 100;
|
||||
pbar.style.width = pct + "%";
|
||||
pbar.text = Io_size.To_str(cur);
|
||||
}
|
||||
public Prog_update_name(String name) {
|
||||
file.text = "unzipping:" + name;
|
||||
}
|
||||
public Prog_update_bgn(long cur) {
|
||||
if (all == 0) {
|
||||
panels.add(this);
|
||||
}
|
||||
all += cur;
|
||||
}
|
||||
public Prog_update_end() {
|
||||
if (cur >= all) {
|
||||
panels.del(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
class pack_prog_bar {
|
||||
public Prog_update_val(long cur, long all) {
|
||||
double pct = (cur / all) * 100;
|
||||
pbar.style.width = pct + "%";
|
||||
pbar.text = Io_size.To_str(cur);
|
||||
}
|
||||
public Prog_update_name(String name) {
|
||||
file.text = "unzipping:" + name;
|
||||
}
|
||||
public Prog_update_bgn() {
|
||||
pbar.visible = true;
|
||||
file.visible = true;
|
||||
file.text = "unzipping: " + ;
|
||||
}
|
||||
public Prog_update_end() {
|
||||
pbar.visible = false;
|
||||
file.visible = false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
25
100_core/src/gplx/core/ios/zips/Io_zip_mgr.java
Normal file
25
100_core/src/gplx/core/ios/zips/Io_zip_mgr.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
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);
|
||||
}
|
||||
120
100_core/src/gplx/core/ios/zips/Io_zip_mgr_base.java
Normal file
120
100_core/src/gplx/core/ios/zips/Io_zip_mgr_base.java
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
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();
|
||||
}
|
||||
37
100_core/src/gplx/core/ios/zips/Io_zip_mgr_mok.java
Normal file
37
100_core/src/gplx/core/ios/zips/Io_zip_mgr_mok.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
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) {}
|
||||
public void Unzip_to_dir_prog(Io_zip_decompress_task task, 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() {}
|
||||
}
|
||||
31
100_core/src/gplx/core/ios/zips/Io_zip_mgr_tst.java
Normal file
31
100_core/src/gplx/core/ios/zips/Io_zip_mgr_tst.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.zips; import gplx.*; import gplx.core.*; import gplx.core.ios.*;
|
||||
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);
|
||||
}
|
||||
}
|
||||
44
100_core/src/gplx/core/primitives/Int_list.java
Normal file
44
100_core/src/gplx/core/primitives/Int_list.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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;
|
||||
}
|
||||
}
|
||||
27
100_core/src/gplx/core/progs/Gfo_prog_task.java
Normal file
27
100_core/src/gplx/core/progs/Gfo_prog_task.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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.progs; import gplx.*; import gplx.core.*;
|
||||
public interface Gfo_prog_task {
|
||||
Gfo_prog_task Prog__owner();
|
||||
long Prog__all();
|
||||
long Prog__cur();
|
||||
void Prog__start();
|
||||
void Prog__cancel();
|
||||
void Prog__pause();
|
||||
void Prog__resume();
|
||||
}
|
||||
21
100_core/src/gplx/core/progs/Gfo_prog_task_.java
Normal file
21
100_core/src/gplx/core/progs/Gfo_prog_task_.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.progs; import gplx.*; import gplx.core.*;
|
||||
public class Gfo_prog_task_ {
|
||||
public static final Gfo_prog_task Null = null;
|
||||
}
|
||||
22
100_core/src/gplx/core/progs/Gfo_prog_ui.java
Normal file
22
100_core/src/gplx/core/progs/Gfo_prog_ui.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.progs; import gplx.*; import gplx.core.*;
|
||||
public interface Gfo_prog_ui {
|
||||
void Prog__update_val(long cur, long max);
|
||||
void Prog__end();
|
||||
}
|
||||
@@ -32,5 +32,12 @@ public class Thread_adp_ {
|
||||
public static void Run_invk_msg(String name, GfoInvkAble invk, GfoMsg m) {
|
||||
Thread_adp_.invk_msg_(name, invk, m).Start();
|
||||
}
|
||||
public static final String Name_null = null;
|
||||
public static void Run_cmd(boolean async, String thread_name, GfoInvkAble invk, String cmd) {
|
||||
GfoMsg msg = GfoMsg_.new_cast_(cmd);
|
||||
if (async)
|
||||
Thread_adp_.invk_msg_(thread_name, invk, msg).Start();
|
||||
else
|
||||
GfoInvkAble_.InvkCmd_msg(invk, cmd, msg);
|
||||
}
|
||||
public static final String Name_null = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user