[libinline-java-perl] 358/398: ok

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:43:23 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 16e7f213ee6be47c55419a007abed6e0d92390c9
Author: patrick_leb <>
Date:   Mon Oct 3 00:26:48 2005 +0000

    ok
---
 Java/Protocol.pm                                   |  3 +-
 .../org/perl/inline/java/InlineJavaProtocol.java   | 52 ++++++++++------
 .../org/perl/inline/java/InlineJavaServer.java     | 16 ++---
 .../perl/inline/java/InlineJavaServerThread.java   | 10 ---
 t/01_init.t                                        |  3 -
 t/14_encoding.t                                    | 71 ++++++++++++++++++++++
 6 files changed, 112 insertions(+), 43 deletions(-)

diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index 49103c0..e99030f 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -54,9 +54,8 @@ sub ServerType {
 	Inline::Java::debug(3, "getting server type") ;
 
 	my $data = "server_type" ;
-	my $info = $this->Send($data) ;
 
-	return split("\n", $info) ;
+	return $this->Send($data) ;
 }
 
 
diff --git a/Java/sources/org/perl/inline/java/InlineJavaProtocol.java b/Java/sources/org/perl/inline/java/InlineJavaProtocol.java
index bc6d73b..bd50fc1 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaProtocol.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaProtocol.java
@@ -15,7 +15,7 @@ class InlineJavaProtocol {
 	private InlineJavaArray ija ;
 	private String cmd ;
 	private String response = null ;
-	// For later use maybe...
+
 	private String encoding = "UTF-8" ;
 
 	static private HashMap member_cache = new HashMap() ;
@@ -796,25 +796,43 @@ class InlineJavaProtocol {
 	}
 
 
-	String Decode(String s){
-		// try {
-			return new String(InlineJavaUtils.DecodeBase64(s.toCharArray())) ;
-		// }
-		// catch (UnsupportedEncodingException e){
-		// 	e.printStackTrace() ;
-		// 	return null ;
-		// }
+	byte[] DecodeToByteArray(String s){
+		return InlineJavaUtils.DecodeBase64(s.toCharArray()) ;
+	}
+
+
+	String Decode(String s) throws InlineJavaException {
+		try {
+			if (encoding != null){
+				return new String(DecodeToByteArray(s), encoding) ;
+			}
+			else {
+				return new String(DecodeToByteArray(s)) ;
+			}
+		}
+		catch (UnsupportedEncodingException e){
+			throw new InlineJavaException("Unsupported encoding: " + e.getMessage()) ;
+		}
 	}
 
 
-	String Encode(String s){
-		// try {
-			return new String(InlineJavaUtils.EncodeBase64(s.getBytes())) ;
-		// }
-		// catch (UnsupportedEncodingException e){
-		// 	e.printStackTrace() ;
-		// 	return null ;
-		// }
+	String EncodeFromByteArray(byte bytes[]){
+		return new String(InlineJavaUtils.EncodeBase64(bytes)) ;
+	}
+
+
+	String Encode(String s) throws InlineJavaException {
+		try {
+			if (encoding != null){
+				return EncodeFromByteArray(s.getBytes(encoding)) ;
+			}
+			else {
+				return EncodeFromByteArray(s.getBytes()) ;
+			}
+		}
+		catch (UnsupportedEncodingException e){
+			throw new InlineJavaException("Unsupported encoding: " + e.getMessage()) ;
+		}
 	}
 
 
diff --git a/Java/sources/org/perl/inline/java/InlineJavaServer.java b/Java/sources/org/perl/inline/java/InlineJavaServer.java
index 018e3bf..2150a6e 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaServer.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaServer.java
@@ -23,8 +23,6 @@ public class InlineJavaServer {
 	private boolean jni = false ;
 	private Thread creator = null ;
 	private int thread_count = 0 ;
-	private String file_encoding = null ;
-	private String socket_encodings = null ;
 
 
 	// This constructor is used in JNI mode
@@ -62,10 +60,6 @@ public class InlineJavaServer {
 				String name = "IJST-#" + thread_count++ ;
 				InlineJavaServerThread ijt = new InlineJavaServerThread(name, this, server_socket.accept(),
 					(priv ? new InlineJavaUserClassLoader() : ijucl)) ;
-				if (socket_encodings == null){
-					file_encoding = System.getProperty("file.encoding") ;
-					socket_encodings = ijt.GetEncodings() ;
-				}
 				ijt.start() ;
 				if (! shared_jvm){
 					try {
@@ -116,9 +110,7 @@ public class InlineJavaServer {
 
 
 	String GetType(){
-		return (shared_jvm ? "shared" : "private") + 
-			"\n" + file_encoding +
-			"\n" + socket_encodings ;
+		return (shared_jvm ? "shared" : "private") ; 
 	}
 
 
@@ -148,7 +140,9 @@ public class InlineJavaServer {
 				resp = ijp.GetResponse() ;
 			}
 			catch (InlineJavaException e){
-				String err = "error scalar:" + ijp.Encode(e.getMessage()) ;
+				// Encode the error in default encoding since we don't want any
+				// Exceptions thrown here...
+				String err = "error scalar:" + ijp.EncodeFromByteArray(e.getMessage().getBytes()) ;
 				InlineJavaUtils.debug(3, "packet sent is " + err) ;
 				resp = err ;
 			}
@@ -310,7 +304,7 @@ public class InlineJavaServer {
 
 
 	/*
-		With PerlInterpreter this is called twisce, but we don't want to create
+		With PerlInterpreter this is called twice, but we don't want to create
 		a new object the second time.
 	*/
 	public static InlineJavaServer jni_main(int debug){
diff --git a/Java/sources/org/perl/inline/java/InlineJavaServerThread.java b/Java/sources/org/perl/inline/java/InlineJavaServerThread.java
index 77234d4..e39e4e9 100644
--- a/Java/sources/org/perl/inline/java/InlineJavaServerThread.java
+++ b/Java/sources/org/perl/inline/java/InlineJavaServerThread.java
@@ -11,8 +11,6 @@ class InlineJavaServerThread extends Thread {
 	private BufferedReader br ;
 	private BufferedWriter bw ;
 	private InlineJavaUserClassLoader ijucl ;
-	private String encoding_in = null ;
-	private String encoding_out = null ;
 
 
 	InlineJavaServerThread(String name, InlineJavaServer _ijs, Socket _client, InlineJavaUserClassLoader _ijucl) throws IOException {
@@ -23,9 +21,6 @@ class InlineJavaServerThread extends Thread {
 
 		InputStreamReader ir = new InputStreamReader(client.getInputStream()) ;
 		OutputStreamWriter or = new OutputStreamWriter(client.getOutputStream()) ;
-		encoding_in = ir.getEncoding() ;
-		encoding_out = or.getEncoding() ;
-
 		br = new BufferedReader(ir) ;
 		bw = new BufferedWriter(or) ;
 	}
@@ -41,11 +36,6 @@ class InlineJavaServerThread extends Thread {
 	}
 
 	
-	String GetEncodings(){
-		return encoding_in + "/" + encoding_out ;
-	}
-
-
 	InlineJavaUserClassLoader GetUserClassLoader(){
 		return ijucl ;
 	}
diff --git a/t/01_init.t b/t/01_init.t
index d96a376..83b0a60 100644
--- a/t/01_init.t
+++ b/t/01_init.t
@@ -19,14 +19,11 @@ $ij = $types1::INLINE ; # Stupid warning...
 my $jdk = $ij->get_java_config("J2SDK") ;
 my $ver = types1->version() ;
 
-my $pc = new Inline::Java::Protocol(undef, $ij) ;
-my ($st, $file_enc, $sock_encs) = $pc->ServerType() ;
 print STDERR "\nPerl version is $]\n" ;
 print STDERR "Inline version is $Inline::VERSION\n" ;
 print STDERR "Inline::Java version is $Inline::Java::VERSION\n" ;
 
 print STDERR "J2SDK version is $ver, from $jdk\n" ;
-print STDERR "Java encodings are file: $file_enc, stream: $sock_encs\n" ;
 print STDERR "CLASSPATH is $main::cp\n" ;
 
 if ($ENV{PERL_INLINE_JAVA_EMBEDDED_JNI}){
diff --git a/t/14_encoding.t b/t/14_encoding.t
new file mode 100755
index 0000000..7b3b801
--- /dev/null
+++ b/t/14_encoding.t
@@ -0,0 +1,71 @@
+use strict ;
+use Test ;
+
+use Inline Config => 
+           DIRECTORY => './_Inline_test' ;
+
+use Inline (
+	Java => 'DATA'
+) ;
+
+
+BEGIN {
+	plan(tests => 9) ;
+}
+
+
+my $t = new t14() ;
+
+{
+	ok($t->_String("A"), "A") ;
+	ok($t->_String("\x{41}"), "A") ;
+	ok($t->_String("A"), "\x{41}") ;
+
+	# This is E9 (233), which is e acute. Although the byte
+	# E9 is invalid in UTF-8, the character 233 is valid and 
+	# all should work out.
+	ok($t->_String("\x{E9}"), "\x{E9}") ;
+	my $a = $t->toCharArray("\x{E9}") ;
+	ok(ord($a->[0]) == 233) ;
+
+	# Send a unicode escape sequence.
+	ok($t->_String("\x{263A}"), "\x{263A}") ;
+
+	# Generate some binary data
+	my $bin = '' ;
+	for (my $i = 0; $i < 256 ; $i++) {
+		my $c = chr($i) ;
+		$bin .= $c ;
+	}
+	ok($t->_String($bin), $bin) ;
+
+	# Mix it up
+	ok($t->_String("$bin\x{E9}\x{263A}"), "$bin\x{E9}\x{263A}") ;
+
+
+}
+
+ok($t->__get_private()->{proto}->ObjectCount(), 1) ;
+
+
+
+
+__END__
+
+__Java__
+
+class t14 {
+	public t14(){
+	}
+
+	public String _String(String s){
+		return s ;
+	}
+
+
+	public char [] toCharArray(String s){
+		return s.toCharArray() ;
+	}
+}
+
+

-- 
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