[libinline-java-perl] 350/398: ok
Jonas Smedegaard
dr at jones.dk
Thu Feb 26 11:43:22 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.55
in repository libinline-java-perl.
commit 70fcc537ca450de05d6f79cde5686de6b81552cc
Author: patrick_leb <>
Date: Sun Sep 4 15:13:15 2005 +0000
ok
---
Java.pm | 2 +-
Java/PerlInterpreter/t/02_perl_interpreter.t | 40 +++++-
.../perl/inline/java/InlineJavaCallbackQueue.java | 2 +-
.../org/perl/inline/java/InlineJavaProtocol.java | 139 +++++++++++++++++----
.../org/perl/inline/java/InlineJavaUtils.java | 109 ++++++++++++++++
Makefile.PL | 2 +
TODO | 5 +-
7 files changed, 271 insertions(+), 28 deletions(-)
diff --git a/Java.pm b/Java.pm
index e34f2ca..95097e4 100644
--- a/Java.pm
+++ b/Java.pm
@@ -8,7 +8,7 @@ package Inline::Java ;
use strict ;
require 5.006 ;
-$Inline::Java::VERSION = '0.50' ;
+$Inline::Java::VERSION = '0.50_90' ;
# DEBUG is set via the DEBUG config
diff --git a/Java/PerlInterpreter/t/02_perl_interpreter.t b/Java/PerlInterpreter/t/02_perl_interpreter.t
index 5624b9d..5448413 100644
--- a/Java/PerlInterpreter/t/02_perl_interpreter.t
+++ b/Java/PerlInterpreter/t/02_perl_interpreter.t
@@ -48,7 +48,10 @@ sub run_java {
my $cmd = Inline::Java::Portable::portable("SUB_FIX_CMD_QUOTES", "\"$java\" " .
"org.perl.inline.java.InlineJavaPerlInterpreterTests $debug") ;
Inline::Java::debug(1, "Command is $cmd\n") ;
- print `$cmd` ;
+ open(CMD, "$cmd|") or die("Can't execute $cmd: $!") ;
+ while (<CMD>){
+ print $_ ;
+ }
}
@@ -57,8 +60,12 @@ __END__
__Java__
package org.perl.inline.java ;
-class InlineJavaPerlInterpreterTests extends InlineJavaPerlInterpreter {
+class InlineJavaPerlInterpreterTests implements Runnable {
private static int cnt = 2 ;
+ private static InlineJavaPerlInterpreter pi = null ;
+ private static int nb_callbacks_to_run = 5 ;
+ private static int nb_callbacks_run = 0 ;
+
private InlineJavaPerlInterpreterTests() throws InlineJavaException, InlineJavaPerlException {
}
@@ -74,6 +81,24 @@ class InlineJavaPerlInterpreterTests extends InlineJavaPerlInterpreter {
cnt++ ;
}
+
+ public void run(){
+ try {
+ String name = (String)pi.CallPerlSub("whats_your_name", null, String.class) ;
+ ok(name, "perl") ;
+ nb_callbacks_run++ ;
+
+ if (nb_callbacks_run == nb_callbacks_to_run){
+ pi.StopCallbackLoop() ;
+ }
+ }
+ catch (Exception e){
+ e.printStackTrace() ;
+ System.exit(1) ;
+ }
+ }
+
+
public static void main(String args[]){
try {
int debug = 0 ;
@@ -82,8 +107,8 @@ class InlineJavaPerlInterpreterTests extends InlineJavaPerlInterpreter {
InlineJavaUtils.debug = debug ;
}
- init("test") ;
- InlineJavaPerlInterpreter pi = InlineJavaPerlInterpreter.create() ;
+ InlineJavaPerlInterpreter.init("test") ;
+ pi = InlineJavaPerlInterpreter.create() ;
pi.require("t/Tests.pl") ;
ok("1", "1") ;
@@ -93,6 +118,13 @@ class InlineJavaPerlInterpreterTests extends InlineJavaPerlInterpreter {
ok(sum, new Integer(90)) ;
String name = (String)pi.CallPerlSub("whats_your_name", null, String.class) ;
ok(name, "perl") ;
+
+ for (int i = 1 ; i <= nb_callbacks_to_run ; i++){
+ Thread t = new Thread(new InlineJavaPerlInterpreterTests()) ;
+ t.start() ;
+ }
+
+ pi.StartCallbackLoop();
pi.destroy() ;
ok("1", "1") ;
diff --git a/Java/sources/org/perl/inline/java/InlineJavaCallbackQueue.java b/Java/sources/org/perl/inline/java/InlineJavaCallbackQueue.java
index 10695f5..de57ef5 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaCallbackQueue.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaCallbackQueue.java
@@ -32,7 +32,7 @@ class InlineJavaCallbackQueue {
synchronized InlineJavaCallback WaitForCallback(){
- while (IsEmpty()){
+ while ((! stop_loop)&&(IsEmpty())){
try {
wait() ;
}
diff --git a/Java/sources/org/perl/inline/java/InlineJavaProtocol.java b/Java/sources/org/perl/inline/java/InlineJavaProtocol.java
index 97399ef..2f5177c 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaProtocol.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaProtocol.java
@@ -1,6 +1,7 @@
package org.perl.inline.java ;
import java.util.* ;
+import java.io.* ;
import java.lang.reflect.* ;
@@ -67,6 +68,21 @@ class InlineJavaProtocol {
else if (c.equals("cast")){
Cast(st) ;
}
+ else if (c.equals("read")){
+ Read(st) ;
+ }
+ else if (c.equals("make_buffered")){
+ MakeBuffered(st) ;
+ }
+ else if (c.equals("readline")){
+ ReadLine(st) ;
+ }
+ else if (c.equals("write")){
+ Write(st) ;
+ }
+ else if (c.equals("close")){
+ Close(st) ;
+ }
else if (c.equals("die")){
InlineJavaUtils.debug(1, "received a request to die...") ;
ijs.Shutdown() ;
@@ -303,6 +319,98 @@ class InlineJavaProtocol {
/*
+ */
+ void Read(StringTokenizer st) throws InlineJavaException {
+ int id = Integer.parseInt(st.nextToken()) ;
+ int len = Integer.parseInt(st.nextToken()) ;
+
+ Object o = ijs.GetObject(id) ;
+ Object ret = null ;
+ try {
+ ret = InlineJavaHandle.read(o, len) ;
+ }
+ catch (java.io.IOException e){
+ ret = new InlineJavaThrown(e) ;
+ }
+
+ SetResponse(ret) ;
+ }
+
+
+ void MakeBuffered(StringTokenizer st) throws InlineJavaException {
+ int id = Integer.parseInt(st.nextToken()) ;
+
+ Object o = ijs.GetObject(id) ;
+ Object ret = null ;
+ try {
+ ret = InlineJavaHandle.makeBuffered(o) ;
+ if (ret != o){
+ int buf_id = ijs.PutObject(ret) ;
+ ret = new Integer(buf_id) ;
+ }
+ else {
+ ret = new Integer(id) ;
+ }
+ }
+ catch (java.io.IOException e){
+ ret = new InlineJavaThrown(e) ;
+ }
+
+ SetResponse(ret) ;
+ }
+
+
+ void ReadLine(StringTokenizer st) throws InlineJavaException {
+ int id = Integer.parseInt(st.nextToken()) ;
+
+ Object o = ijs.GetObject(id) ;
+ Object ret = null ;
+ try {
+ ret = InlineJavaHandle.readLine(o) ;
+ }
+ catch (java.io.IOException e){
+ ret = new InlineJavaThrown(e) ;
+ }
+
+ SetResponse(ret) ;
+ }
+
+
+ void Write(StringTokenizer st) throws InlineJavaException {
+ int id = Integer.parseInt(st.nextToken()) ;
+ Object arg = ijc.CastArgument(Object.class, st.nextToken()) ;
+
+ Object o = ijs.GetObject(id) ;
+ Object ret = null ;
+ try {
+ int len = InlineJavaHandle.write(o, arg.toString()) ;
+ ret = new Integer(len) ;
+ }
+ catch (java.io.IOException e){
+ ret = new InlineJavaThrown(e) ;
+ }
+
+ SetResponse(ret) ;
+ }
+
+
+ void Close(StringTokenizer st) throws InlineJavaException {
+ int id = Integer.parseInt(st.nextToken()) ;
+
+ Object o = ijs.GetObject(id) ;
+ Object ret = null ;
+ try {
+ InlineJavaHandle.close(o) ;
+ }
+ catch (java.io.IOException e){
+ ret = new InlineJavaThrown(e) ;
+ }
+
+ SetResponse(ret) ;
+ }
+
+
+ /*
Sets a Java member variable
*/
void SetJavaMember(StringTokenizer st) throws InlineJavaException {
@@ -661,14 +769,21 @@ class InlineJavaProtocol {
// Here we need to register the object in order to send
// it back to the Perl script.
boolean thrown = false ;
+ String type = "object" ;
if (o instanceof InlineJavaThrown){
thrown = true ;
o = ((InlineJavaThrown)o).GetThrowable() ;
c = o.getClass() ;
}
+ else if (ijc.ClassIsArray(c)){
+ type = "array" ;
+ }
+ else if (ijc.ClassIsHandle(c)){
+ type = "handle" ;
+ }
int id = ijs.PutObject(o) ;
- return "java_object:" + (thrown ? "1" : "0") + ":" + String.valueOf(id) +
+ return "java_" + type + ":" + (thrown ? "1" : "0") + ":" + String.valueOf(id) +
":" + c.getName() ;
}
else {
@@ -680,30 +795,12 @@ class InlineJavaProtocol {
String Decode(String s){
- StringTokenizer st = new StringTokenizer(s, ".") ;
- StringBuffer sb = new StringBuffer() ;
- while (st.hasMoreTokens()){
- String ss = st.nextToken() ;
- char c = (char)Integer.parseInt(ss) ;
- sb.append(new String(new char [] {c})) ;
- }
-
- return sb.toString() ;
+ return new String(InlineJavaUtils.DecodeBase64(s.toCharArray())) ;
}
String Encode(String s){
- char c[] = new char[s.length()] ;
- s.getChars(0, c.length, c, 0) ;
- StringBuffer sb = new StringBuffer() ;
- for (int i = 0 ; i < c.length ; i++){
- if (i > 0){
- sb.append(".") ;
- }
- sb.append((int)c[i]) ;
- }
-
- return sb.toString() ;
+ return new String(InlineJavaUtils.EncodeBase64(s.getBytes())) ;
}
diff --git a/Java/sources/org/perl/inline/java/InlineJavaUtils.java b/Java/sources/org/perl/inline/java/InlineJavaUtils.java
index 0459f01..b6191f1 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaUtils.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaUtils.java
@@ -53,4 +53,113 @@ class InlineJavaUtils {
return (! no_rev) ;
}
+
+
+
+ /*
+ Base64 stuff. This section conatins code by Christian d'Heureuse that is
+ licended under the GPL. Used by permission:
+
+ From: Christian d'Heureuse <chdh at inventec.ch>
+ To: Patrick LeBoutillier <patrick.leboutillier at gmail.com>
+ Date: Aug 11, 2005 4:45 AM
+ Subject: Re: Base64Coder
+
+ > I was wondering if you can grant me permission to include your
+ > code in my project.
+
+ Yes, I grant you permission to include the Base64Coder class in your
+ project.
+
+ *
+ * A Base64 Encoder/Decoder.
+ *
+ * This class is used to encode and decode data in Base64 format
+ * as described in RFC 1521.
+ *
+ * <p>
+ * Copyright 2003: Christian d'Heureuse, Inventec Informatik AG, Switzerland.<br>
+ * License: This is "Open Source" software and released under the <a href="http://www.gnu.org/licenses/lgpl.html" target="_top">GNU/LGPL</a> license.
+ * It is provided "as is" without warranty of any kind. Please contact the author for other licensing arrangements.<br>
+ * Home page: <a href="http://www.source-code.biz" target="_top">www.source-code.biz</a><br>
+ *
+ * <p>
+ * Version history:<br>
+ * 2003-07-22 Christian d'Heureuse (chdh): Module created.<br>
+ * 2005-08-11 chdh: Lincense changed from GPL to LGPL.
+ *
+ */
+
+ // Mapping table from 6-bit nibbles to Base64 characters.
+ private static char[] map1 = new char[64];
+ static {
+ int i=0;
+ for (char c='A'; c<='Z'; c++) map1[i++] = c;
+ for (char c='a'; c<='z'; c++) map1[i++] = c;
+ for (char c='0'; c<='9'; c++) map1[i++] = c;
+ map1[i++] = '+'; map1[i++] = '/';
+ }
+
+ // Mapping table from Base64 characters to 6-bit nibbles.
+ private static byte[] map2 = new byte[128];
+ static {
+ for (int i=0; i<map2.length; i++) map2[i] = -1;
+ for (int i=0; i<64; i++) map2[map1[i]] = (byte)i;
+ }
+
+
+ public static char[] EncodeBase64(byte[] in){
+ int iLen = in.length;
+ int oDataLen = (iLen*4+2)/3; // output length without padding
+ int oLen = ((iLen+2)/3)*4; // output length including padding
+ char[] out = new char[oLen];
+ int ip = 0;
+ int op = 0;
+ while (ip < iLen) {
+ int i0 = in[ip++] & 0xff;
+ int i1 = ip < iLen ? in[ip++] & 0xff : 0;
+ int i2 = ip < iLen ? in[ip++] & 0xff : 0;
+ int o0 = i0 >>> 2;
+ int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
+ int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
+ int o3 = i2 & 0x3F;
+ out[op++] = map1[o0];
+ out[op++] = map1[o1];
+ out[op] = op < oDataLen ? map1[o2] : '='; op++;
+ out[op] = op < oDataLen ? map1[o3] : '='; op++;
+ }
+ return out;
+ }
+
+
+ public static byte[] DecodeBase64(char[] in){
+ int iLen = in.length;
+ if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input string is not a multiple of 4.");
+ while (iLen > 0 && in[iLen-1] == '=') iLen--;
+ int oLen = (iLen*3) / 4;
+ byte[] out = new byte[oLen];
+ int ip = 0;
+ int op = 0;
+ while (ip < iLen) {
+ int i0 = in[ip++];
+ int i1 = in[ip++];
+ int i2 = ip < iLen ? in[ip++] : 'A';
+ int i3 = ip < iLen ? in[ip++] : 'A';
+ if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
+ throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
+ int b0 = map2[i0];
+ int b1 = map2[i1];
+ int b2 = map2[i2];
+ int b3 = map2[i3];
+ if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
+ throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
+ int o0 = ( b0 <<2) | (b1>>>4);
+ int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
+ int o2 = ((b2 & 3)<<6) | b3;
+ out[op++] = (byte)o0;
+ if (op<oLen) out[op++] = (byte)o1;
+ if (op<oLen) out[op++] = (byte)o2;
+ }
+ return out;
+ }
}
diff --git a/Makefile.PL b/Makefile.PL
index eed03a6..4ff8530 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -157,6 +157,8 @@ WriteMakefile(
PREREQ_PM => {
Inline => 0.44,
Test => 1.13,
+ Encode => 0,
+ 'MIME::Base64' => 0,
},
PM => {
'Java.pm' => File::Spec->catfile('$(INST_LIBDIR)', 'Java.pm'),
diff --git a/TODO b/TODO
index 17baa38..6be55c6 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,11 @@
CODE:
- Finish PerlInterpreter test suite
+- Send doubles and floats bytes instead of string representation to preserve precision. If that
+ doesn't work, use sprintf with a user configurable precision.
+
DOCUMENTATION:
-- Document InlineJavaPerlObject and InlineJavaPerlInterpreter
+- Document InlineJavaPerlObject
TEST:
- Alpha
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git
More information about the Pkg-perl-cvs-commits
mailing list