rjb 1.3.3-universal-darwin-10 → 1.3.4-universal-darwin-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +528 -520
- data/ext/rjb.c +31 -8
- data/lib/rjbcore.bundle +0 -0
- data/samples/unzip.rb +66 -0
- data/test/test.rb +11 -1
- metadata +3 -2
data/ext/rjb.c
CHANGED
@@ -12,10 +12,10 @@
|
|
12
12
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
13
|
* Lesser General Public License for more details.
|
14
14
|
*
|
15
|
-
* $Id: rjb.c
|
15
|
+
* $Id: rjb.c 163 2010-11-22 07:31:27Z arton $
|
16
16
|
*/
|
17
17
|
|
18
|
-
#define RJB_VERSION "1.3.
|
18
|
+
#define RJB_VERSION "1.3.4"
|
19
19
|
|
20
20
|
#include "ruby.h"
|
21
21
|
#include "extconf.h"
|
@@ -75,6 +75,7 @@ static VALUE jarray2rv(JNIEnv* jenv, jvalue val);
|
|
75
75
|
static jarray r2objarray(JNIEnv* jenv, VALUE v, const char* cls);
|
76
76
|
static VALUE jv2rv_withprim(JNIEnv* jenv, jobject o);
|
77
77
|
static J2R get_arrayconv(const char* cname, char* depth);
|
78
|
+
static jarray r2barray(JNIEnv* jenv, VALUE v, const char* cls);
|
78
79
|
|
79
80
|
static VALUE rjb;
|
80
81
|
static VALUE jklass;
|
@@ -748,7 +749,7 @@ static void rv2jstring(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
748
749
|
return; /* never delete at this time */
|
749
750
|
}
|
750
751
|
}
|
751
|
-
|
752
|
+
}
|
752
753
|
(*jenv)->DeleteLocalRef(jenv, jv->l);
|
753
754
|
}
|
754
755
|
}
|
@@ -814,7 +815,11 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
814
815
|
}
|
815
816
|
break;
|
816
817
|
case T_STRING:
|
817
|
-
|
818
|
+
if (psig && *psig == '[' && *(psig + 1) == 'B') {
|
819
|
+
jv->l = r2barray(jenv, val, NULL);
|
820
|
+
} else {
|
821
|
+
rv2jstring(jenv, val, jv, NULL, 0);
|
822
|
+
}
|
818
823
|
break;
|
819
824
|
case T_FLOAT:
|
820
825
|
arg.d = NUM2DBL(val);
|
@@ -1115,6 +1120,22 @@ static void rv2jarray(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
|
|
1115
1120
|
}
|
1116
1121
|
if (release)
|
1117
1122
|
{
|
1123
|
+
if (TYPE(val) == T_STRING && *(psig + 1) == 'B')
|
1124
|
+
{
|
1125
|
+
// copy array's contents into arg string
|
1126
|
+
jsize len = (*jenv)->GetArrayLength(jenv, jv->l);
|
1127
|
+
jbyte* p = (*jenv)->GetByteArrayElements(jenv, jv->l, NULL);
|
1128
|
+
if (len <= RSTRING_LEN(val))
|
1129
|
+
{
|
1130
|
+
memcpy(StringValuePtr(val), p, len);
|
1131
|
+
}
|
1132
|
+
else
|
1133
|
+
{
|
1134
|
+
VALUE src = rb_str_new(p, len);
|
1135
|
+
rb_str_set_len(val, 0);
|
1136
|
+
rb_str_append(val, src);
|
1137
|
+
}
|
1138
|
+
}
|
1118
1139
|
(*jenv)->DeleteLocalRef(jenv, jv->l);
|
1119
1140
|
}
|
1120
1141
|
else
|
@@ -2099,7 +2120,7 @@ static int check_rtype(JNIEnv* jenv, VALUE v, char* p)
|
|
2099
2120
|
case T_FLOAT:
|
2100
2121
|
return strchr("DF", *p) != NULL;
|
2101
2122
|
case T_STRING:
|
2102
|
-
|
2123
|
+
return pcls && !strcmp("java.lang.String", pcls) || *p == '[' && *(p + 1) == 'B';
|
2103
2124
|
case T_TRUE:
|
2104
2125
|
case T_FALSE:
|
2105
2126
|
return *p == 'Z';
|
@@ -3057,11 +3078,13 @@ static VALUE rjb_class_forname(int argc, VALUE* argv, VALUE self)
|
|
3057
3078
|
*/
|
3058
3079
|
void Init_rjbcore()
|
3059
3080
|
{
|
3060
|
-
#if
|
3081
|
+
#if RJB_RUBY_VERSION_CODE < 190
|
3082
|
+
#if defined(RUBINIUS)
|
3061
3083
|
rb_require("iconv");
|
3062
|
-
#else
|
3084
|
+
#else
|
3063
3085
|
rb_protect((VALUE(*)(VALUE))rb_require, (VALUE)"iconv", NULL);
|
3064
|
-
#endif
|
3086
|
+
#endif
|
3087
|
+
#endif
|
3065
3088
|
rjb_loaded_classes = rb_hash_new();
|
3066
3089
|
#ifndef RUBINIUS
|
3067
3090
|
OBJ_FREEZE(rjb_loaded_classes);
|
data/lib/rjbcore.bundle
CHANGED
Binary file
|
data/samples/unzip.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rjb'
|
2
|
+
|
3
|
+
if Rjb::VERSION < '1.3.4'
|
4
|
+
$stderr.puts "require rjb-1.3.4 or later, bye."
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
|
8
|
+
class ZipFile
|
9
|
+
include Enumerable
|
10
|
+
Zip = Rjb::import('java.util.zip.ZipFile')
|
11
|
+
def initialize(file, &block)
|
12
|
+
@zipfile = Zip.new(file)
|
13
|
+
if block
|
14
|
+
yield self
|
15
|
+
@zipfile.close
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def close
|
19
|
+
@zipfile.close
|
20
|
+
end
|
21
|
+
def each(&block)
|
22
|
+
unless block
|
23
|
+
Enumerator.new(self)
|
24
|
+
else
|
25
|
+
e = @zipfile.entries
|
26
|
+
while e.has_more_elements
|
27
|
+
yield e.next_element
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def size
|
32
|
+
@zipfile.size
|
33
|
+
end
|
34
|
+
def unzip(ent)
|
35
|
+
if String === ent
|
36
|
+
ent = @zipfile.entry(ent)
|
37
|
+
end
|
38
|
+
is = @zipfile.input_stream(ent)
|
39
|
+
buff = "\0" * 4096
|
40
|
+
File.open(ent.name, 'wb') do |fout|
|
41
|
+
loop do
|
42
|
+
len = is.read(buff, 0, buff.size)
|
43
|
+
break if len < 0
|
44
|
+
fout.write(buff[0, len])
|
45
|
+
end
|
46
|
+
is.close
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if __FILE__ == $0
|
52
|
+
if ARGV.size == 0
|
53
|
+
puts 'usage: ruby unzip.rb filename'
|
54
|
+
else
|
55
|
+
ARGV.each do |file|
|
56
|
+
ZipFile.new(file) do |zip|
|
57
|
+
zip.each do |f|
|
58
|
+
puts "#{f.name}, #{f.size}"
|
59
|
+
unless f.directory?
|
60
|
+
zip.unzip(f)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/test/test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/local/env ruby -Ku
|
2
2
|
# encoding: utf-8
|
3
|
-
# $Id: test.rb
|
3
|
+
# $Id: test.rb 161 2010-11-22 07:18:00Z arton $
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'rjb'
|
@@ -750,5 +750,15 @@ class TestRjb < Test::Unit::TestCase
|
|
750
750
|
jt = import('jp.co.infoseek.hp.arton.rjb.JarTest')
|
751
751
|
assert_equal 'abcd', jt.new.add('ab', 'cd')
|
752
752
|
end
|
753
|
+
def test_bothdirection_buffer
|
754
|
+
org = "abcdefghijklmn"
|
755
|
+
baip = import('java.io.ByteArrayInputStream')
|
756
|
+
ba = baip.new(org)
|
757
|
+
buff = "\0" * org.size
|
758
|
+
assert_equal org.size, ba.read(buff)
|
759
|
+
assert_equal -1, ba.read(buff)
|
760
|
+
ba.close
|
761
|
+
assert_equal org, buff
|
762
|
+
end
|
753
763
|
end
|
754
764
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rjb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: universal-darwin-10
|
6
6
|
authors:
|
7
7
|
- arton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-11-
|
12
|
+
date: 2010-11-23 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/rjb.rb
|
40
40
|
- lib/rjbextension.rb
|
41
41
|
- samples/filechooser.rb
|
42
|
+
- samples/unzip.rb
|
42
43
|
- test/exttest.rb
|
43
44
|
- test/gctest.rb
|
44
45
|
- test/test.rb
|