IDECommunicator : Change InputStream -> DataInputStream
authorjungwook.ryu <jungwook.ryu@samsung.com>
Tue, 7 Jul 2015 04:04:34 +0000 (13:04 +0900)
committerjungwook.ryu <jungwook.ryu@samsung.com>
Tue, 7 Jul 2015 04:05:16 +0000 (13:05 +0900)
Change-Id: I548062fb9bbac78f5db9291c6da5b6f7a3dcc2e5
Signed-off-by: jungwook.ryu <jungwook.ryu@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/IDECommunicator.java

index 5556f27..aa66705 100644 (file)
 package org.tizen.dynamicanalyzer.communicator;
 
 import java.io.BufferedWriter;
+import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.io.RandomAccessFile;
 import java.net.ServerSocket;
@@ -47,9 +47,9 @@ import java.util.List;
 import org.eclipse.swt.widgets.Display;
 import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
 import org.tizen.dynamicanalyzer.common.DAResult;
-import org.tizen.dynamicanalyzer.common.Global;
-import org.tizen.dynamicanalyzer.common.DAState;
 import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode;
+import org.tizen.dynamicanalyzer.common.DAState;
+import org.tizen.dynamicanalyzer.common.Global;
 import org.tizen.dynamicanalyzer.common.path.PathManager;
 import org.tizen.dynamicanalyzer.constant.CommonConstants;
 import org.tizen.dynamicanalyzer.handlers.CommandAction;
@@ -72,8 +72,6 @@ import org.tizen.dynamicanalyzer.utils.RpmUtil;
 import org.tizen.dynamicanalyzer.workbench.SingletonFocusManager;
 
 public class IDECommunicator implements Runnable {
-       private static final int MAXBUFSIZE = 1024;
-
        private static final String IDE_DA_COMMUNICATION_TYPE_1 = "STATUS";//$NON-NLS-1$
        private static final String IDE_DA_COMMUNICATION_TYPE_2 = "RUN";//$NON-NLS-1$
        private static final String IDE_DA_COMMUNICATION_TYPE_3 = "SOURCE";//$NON-NLS-1$
@@ -140,32 +138,28 @@ public class IDECommunicator implements Runnable {
                                }
 
                                Thread acceptThread = new Thread("IDEAcceptThread") {//$NON-NLS-1$
-                                       int readSize = 0;
-                                       byte receiveBuffer[] = new byte[MAXBUFSIZE];
-                                       InputStream in = null;
+                                       DataInputStream in = null;
 
                                        public void run() {
                                                Socket clientSocket = lastCommunicationIdeSocket;
                                                while (true) {
                                                        try {
-                                                               for (int i = 0; i < receiveBuffer.length; i++) { // clear buffer
-                                                                       receiveBuffer[i] = 0;
-                                                               }
-                                                               in = clientSocket.getInputStream();
+                                                               in = new DataInputStream(clientSocket.getInputStream());
                                                                Logger.debug("IDE recvMessage Wait : "
                                                                                + ideClientSocketArray.size());
-                                                               readSize = in.read(receiveBuffer);
-                                                               if (readSize > 0) {
-                                                                       lastCommunicationIdeSocket = clientSocket;
-                                                                       parsingReceiveMessage(new String(receiveBuffer));
-                                                               } else {
-                                                                       Logger.debug("Disconnected IDE : "
-                                                                                       + ideClientSocketArray.size());
+                                                               String msg = in.readUTF();
+                                                               Logger.debug(msg);
+                                                               lastCommunicationIdeSocket = clientSocket;
+                                                               parsingReceiveMessage(msg);
+                                                       } catch (IOException e) {
+                                                               Logger.debug("Disconnected IDE : "
+                                                                               + ideClientSocketArray.size());
+                                                               try {
                                                                        clientSocket.close();
-                                                                       ideClientSocketArray.remove(clientSocket);
-                                                                       break;
+                                                               } catch (IOException e1) {
+                                                                       Logger.exception(e1);
                                                                }
-                                                       } catch (IOException e) {
+                                                               ideClientSocketArray.remove(clientSocket);
                                                                Logger.exception(e);
                                                                break;
                                                        }