changeset 111:fe8306c6c8bf

*** empty log message ***
author pin
date Sun, 23 Dec 2007 13:54:14 +0900
parents c0157dc9cb75
children 0acf4df243c7
files rep/SessionManager.java
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rep/SessionManager.java	Sun Dec 23 13:02:46 2007 +0900
+++ b/rep/SessionManager.java	Sun Dec 23 13:54:14 2007 +0900
@@ -3,11 +3,16 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
 import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
 import java.util.LinkedList;
 import java.util.StringTokenizer;
 
@@ -155,7 +160,9 @@
 			editor.setHost(myHost);
 			allEditorList.addEditor(editor);
 			editor.setEID(1);
-			editor.setName(receivedCommand.string);
+			String string2 = setUTF16(receivedCommand.string);
+			editor.setName(string2);
+			//editor.setName(receivedCommand.string);
 			session = new Session(editor);
 			session.setOwner(true);
 			session.addEditor(editor);
@@ -377,6 +384,25 @@
 		}
 	}
 
+	private String setUTF16(String string) {
+    	//CharBuffer cb = CharBuffer.wrap(string);
+   		Charset charset = Charset.forName("UTF-16");
+   		ByteBuffer buffer = ByteBuffer.allocateDirect(string.length() * 2);
+		//CharsetEncoder encoder = charset.newEncoder();
+		try {
+			buffer = charset.encode(string);
+		} catch (IllegalStateException e) {
+			e.printStackTrace();
+		}
+		buffer.rewind();
+		String text = null;
+		for(int i=0;i<string.length();i++) {
+			text +=buffer.getChar();
+		}
+		String string2 = text;
+		return string2;
+	}
+
 	private boolean setMaxHost(SocketChannel channel, String host) {
 		if(maxHost == null) {
 			maxHost = myHost;