Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/REPPacketSend.java @ 48:b4991de8e83a
UTF-8 Pack Method packUConv()/unpackUConv() add
author | fuchita |
---|---|
date | Tue, 13 Nov 2007 18:53:24 +0900 |
parents | f4eb7fd098c4 |
children | f8b4101746d2 |
comparison
equal
deleted
inserted
replaced
47:f4eb7fd098c4 | 48:b4991de8e83a |
---|---|
8 import java.nio.charset.CharsetEncoder; | 8 import java.nio.charset.CharsetEncoder; |
9 | 9 |
10 | 10 |
11 public class REPPacketSend { | 11 public class REPPacketSend { |
12 SocketChannel socketchannel; | 12 SocketChannel socketchannel; |
13 | 13 // JIS/S-JIS = 2, UTF-8 = 3, UTF-?? = 5 |
14 final int CHAR_ORDER = 3; | |
15 | |
14 public REPPacketSend(SocketChannel sc){ | 16 public REPPacketSend(SocketChannel sc){ |
15 socketchannel = sc; | 17 socketchannel = sc; |
16 } | 18 } |
17 | 19 |
18 public ByteBuffer pack(REPCommand command){ | 20 public ByteBuffer pack(REPCommand command){ |
35 public ByteBuffer packUConv(REPCommand command){ | 37 public ByteBuffer packUConv(REPCommand command){ |
36 System.out.println("send command byUTF8: " + command.toString()); | 38 System.out.println("send command byUTF8: " + command.toString()); |
37 if(command.string == null){ | 39 if(command.string == null){ |
38 command.setString("test"); | 40 command.setString("test"); |
39 } | 41 } |
40 ByteBuffer buffer = ByteBuffer.allocateDirect(24+(command.string).length()*5); | 42 ByteBuffer buffer = ByteBuffer.allocateDirect(24+(command.string).length()*CHAR_ORDER); |
41 buffer.clear(); // position = 0 | 43 buffer.clear(); // position = 0 |
42 buffer.putInt(command.cmd); buffer.putInt(command.sid); buffer.putInt(command.eid); | 44 buffer.putInt(command.cmd); buffer.putInt(command.sid); buffer.putInt(command.eid); |
43 buffer.putInt(command.seq); buffer.putInt(command.lineno); | 45 buffer.putInt(command.seq); buffer.putInt(command.lineno); |
44 | 46 |
45 int pos = buffer.position(); | 47 int pos = buffer.position(); |
63 return buffer; | 65 return buffer; |
64 } | 66 } |
65 | 67 |
66 public void send(REPCommand command){ | 68 public void send(REPCommand command){ |
67 try { | 69 try { |
68 socketchannel.write(pack(command)); | 70 socketchannel.write(packUConv(command)); |
69 //System.out.println(command.toString()); | 71 //System.out.println(command.toString()); |
70 } catch (IOException e) { | 72 } catch (IOException e) { |
71 e.printStackTrace(); | 73 e.printStackTrace(); |
72 } | 74 } |
73 } | 75 } |