diff rep/REPCommandPacker.java @ 337:5ba5b7a9761b

use REPLogger
author kono
date Sun, 12 Oct 2008 18:42:18 +0900
parents f39a8045175d
children 537a9c6c6d9c
line wrap: on
line diff
--- a/rep/REPCommandPacker.java	Sun Oct 12 18:06:54 2008 +0900
+++ b/rep/REPCommandPacker.java	Sun Oct 12 18:42:18 2008 +0900
@@ -32,7 +32,6 @@
 	private static final int HEADER_SIZE = 24;
 	// JIS/S-JIS = 2, UTF-8 = 3, UTF-?? = 5
 	private static final int CHARSIZE = 5;
-	private static final boolean isLogging=false;
 
 	Charset charset = Charset.forName("UTF-8");
 	CharsetEncoder encoder = charset.newEncoder();
@@ -42,11 +41,6 @@
 	 * @see rep.REPPack#packUConv(rep.REPCommand)
 	 */
 	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()*CHARSIZE));
     	buffer.clear();  // position = 0 
     	buffer.putInt(command.cmd.id);
@@ -58,14 +52,16 @@
     	int pos = buffer.position();
     	buffer.putInt(0);
     	int pos1 = buffer.position();
-    	
-    	//Encode to UTF8
-    	CharBuffer cb = CharBuffer.wrap(command.string);
-		try {
-			encoder.encode(cb, buffer, true);
-		} catch (IllegalStateException e) {
-			buffer.position(pos1);
-		}
+
+    	if (command.string!=null) {
+    		//Encode to UTF8
+    		CharBuffer cb = CharBuffer.wrap(command.string);
+    		try {
+    			encoder.encode(cb, buffer, true);
+    		} catch (IllegalStateException e) {
+    			buffer.position(pos1);
+    		}
+    	}
 		
 		//Encoded string length set
 		int length = buffer.position() -pos1 ;
@@ -117,8 +113,8 @@
 		}
 		textsiz = string.length();
 		REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string);
-		if (isLogging)
-			System.out.println("Reading: "+repcommand);
+		//if (isLogging)
+		//System.out.println("Reading: "+repcommand);
 		return repcommand;		
 	}