Mercurial > hg > RemoteEditor > REPSessionManager
changeset 312:f39a8045175d
*** empty log message ***
author | kono |
---|---|
date | Sun, 05 Oct 2008 11:39:18 +0900 |
parents | 7107faaf3feb |
children | 0585fd2410b8 |
files | rep/REPCommandPacker.java |
diffstat | 1 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/REPCommandPacker.java Sun Oct 05 11:26:04 2008 +0900 +++ b/rep/REPCommandPacker.java Sun Oct 05 11:39:18 2008 +0900 @@ -29,9 +29,10 @@ public class REPCommandPacker implements REPPack<REPCommand> { private static final int TEXTSIZELIMIT = 0x7000000; + private static final int HEADER_SIZE = 24; // JIS/S-JIS = 2, UTF-8 = 3, UTF-?? = 5 - private final int HEADER_SIZE = 24; - final int CHAR_ORDER = 5; + private static final int CHARSIZE = 5; + private static final boolean isLogging=false; Charset charset = Charset.forName("UTF-8"); CharsetEncoder encoder = charset.newEncoder(); @@ -40,12 +41,13 @@ /* (non-Javadoc) * @see rep.REPPack#packUConv(rep.REPCommand) */ - public ByteBuffer packUConv(REPCommand command){ - System.out.println("send command byUTF8: " + command.toString()); + public ByteBuffer packUConv(REPCommand command){ + if (isLogging) + System.out.println("Sending: " + command); if(command.string == null){ command.setString(""); } - ByteBuffer buffer = ByteBuffer.allocateDirect(HEADER_SIZE+(command.string.length()*CHAR_ORDER)); + ByteBuffer buffer = ByteBuffer.allocateDirect(HEADER_SIZE+(command.string.length()*CHARSIZE)); buffer.clear(); // position = 0 buffer.putInt(command.cmd.id); buffer.putInt(command.sid); @@ -67,7 +69,6 @@ //Encoded string length set int length = buffer.position() -pos1 ; - // System.out.println("UTF-8: Set REPComand textlen(Byte) : " + (buffer.position() - pos-4)); buffer.putInt(pos, length); buffer.limit(HEADER_SIZE+length); buffer.rewind(); @@ -82,7 +83,7 @@ while(header.remaining()>0){ if (sc.read(header)<0) throw new IOException(); - } // 壊れたパケットに対してはブロックする可能性あり まぁTCPだしいいか? + } header.rewind(); // position = 0 @@ -105,9 +106,9 @@ textBuffer.rewind(); //Decode UTF-8 to System Encoding(UTF-16) - CharBuffer cb = null; String string; try { + CharBuffer cb; cb = decoder.decode(textBuffer); cb.rewind(); string = cb.toString(); @@ -116,6 +117,8 @@ } textsiz = string.length(); REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); + if (isLogging) + System.out.println("Reading: "+repcommand); return repcommand; }