import java.net.Socket;
 import java.net.SocketException;
 import java.net.UnknownHostException;
-import java.lang.NumberFormatException;
 
 
 public class AlarmTaskThread extends Thread {
 
     private boolean isStop = false;
     private CollectVo collectVo = null;
-    private int read_timeout = Constant.READ_TIMEOUT_MILLISECOND;
+    private int readTimeout = Constant.READ_TIMEOUT_MILLISECOND;
     private int reqId;
 
     private Socket socket = null;
                        boolean suc = this.ackLoginAlarm(msg);
                        if (suc) {
 
-                           if (reqId == Integer.MAX_VALUE) reqId=0;
+                           if (reqId == Integer.MAX_VALUE) 
+                               reqId=0;
+
                            reqId++;
                            Msg msgheart = MessageUtil.putHeartBeatMsg(reqId);
                            heartBeat = new HeartBeat(socket, msgheart);
        }
 }
 
-    public void init() throws NumberFormatException, IOException{
+    public void init() throws IOException{
         isStop = false;
         //host
         String host = collectVo.getIP();
         String password = collectVo.getPassword();
 
        try{
-               if((collectVo.getRead_timeout()).trim().length()>0) this.read_timeout = Integer.parseInt(collectVo.getRead_timeout());
+               if((collectVo.getRead_timeout()).trim().length()>0) 
+                       this.readTimeout = Integer.parseInt(collectVo.getRead_timeout());
 
        } catch (NumberFormatException e) {
                log.error("Unable to parse read_timout: ",e);
             throw new SocketException("create socket IOException " + e1);
         }
         try {
-            socket.setSoTimeout(this.read_timeout);
+            socket.setSoTimeout(this.readTimeout);
             socket.setTcpNoDelay(true);
             socket.setKeepAlive(true);
         } catch (SocketException e) {
     }
 
     private boolean ackLoginAlarm(Msg msg) throws IOException {
-        boolean is_success = false;
+        boolean ret = false;
        try {
                String loginres = msg.getBody();
                String[] loginbody = loginres.split(";");
                                if (str.contains("=")) {
                                        String[] paras1 = str.split("=", -1);
                                        if ("result".equalsIgnoreCase(paras1[0].trim())) {
-                                               if("succ".equalsIgnoreCase(paras1[1].trim())) is_success = true; 
-                                               else is_success = false;
+                                               if("succ".equalsIgnoreCase(paras1[1].trim())) 
+                                                       ret = true; 
+                                               else ret = false;
                                        }
                                }
                        }
        } catch (Exception e) {
             log.error("pocess login ack fail" + StringUtil.getStackTrace(e));
         }
-        if (is_success) {
+        if (ret) {
             log.info("login sucess receive login ack " + msg.getBody());
         } else {
             log.error("login fail receive login ack  " + msg.getBody());
             this.isStop = true;
            throw new IOException("pocess login ack fail");
         }
-        return is_success;
+        return ret;
     }
 
     public void close() {
 
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onap.vfc.nfvo.emsdriver.collector.alarm;
 
 import java.io.*;
 
     public static Msg putLoginMsg(String user, String passwd) {
         String body = String.format(Msg.reqLoginAlarm, user, passwd, "msg");
-        Msg msg = new Msg(body, MsgType.reqLoginAlarm);
-
-
-        return msg;
+        return new Msg(body, MsgType.reqLoginAlarm);
 
     }
 
     public static Msg putLoginFtp(String user, String passwd) {
         String body = String.format(Msg.reqLoginAlarm, user, passwd, "ftp");
-        Msg msg = new Msg(body, MsgType.reqLoginAlarm);
-
-
-        return msg;
+       return new Msg(body, MsgType.reqLoginAlarm);
 
     }
 
     public static Msg putSyncMsg(int reqId, int alarmSeq) {
         String body = String.format(Msg.syncAlarmMessageMsg, reqId, alarmSeq);
-        Msg msg = new Msg(body, MsgType.reqSyncAlarmMsg);
-
-
-        return msg;
+        return new Msg(body, MsgType.reqSyncAlarmMsg);
 
     }
 
     public static Msg putHeartBeatMsg(int reqId) {
         String body = String.format(Msg.reqHeartBeat, reqId);
-        Msg msg = new Msg(body, MsgType.reqHeartBeat);
-        return msg;
+        return new Msg(body, MsgType.reqHeartBeat);
 
     }
 
     public static Msg reqSyncAlarmFile(int reqId, String startTime, String endTime) {
         String body = String.format(Msg.syncActiveAlarmFileMsg, reqId, startTime, endTime);
-        Msg msg = new Msg(body, MsgType.reqSyncAlarmFile);
-        return msg;
+        return new Msg(body, MsgType.reqSyncAlarmFile);
     }
 
     public static Msg reqSyncAlarmFileByAlarmSeq(int reqId, int alarmSeq) {
         String body = String.format(Msg.syncAlarmMessageByalarmSeq, reqId, alarmSeq);
-        Msg msg = new Msg(body, MsgType.reqSyncAlarmFile);
-        return msg;
+        return new Msg(body, MsgType.reqSyncAlarmFile);
     }
 
     public static Msg reqSyncAlarmFileByTime(int reqId, String startTime, String endTime) {
         String body = String.format(Msg.syncAlarmFileMsg, reqId, startTime, endTime);
-        Msg msg = new Msg(body, MsgType.reqSyncAlarmFile);
-        return msg;
+        return new Msg(body, MsgType.reqSyncAlarmFile);
     }
 
     public static Msg closeConnAlarmMsg() {
         String body = String.format(Msg.disconnectMsg);
-        Msg msg = new Msg(body, MsgType.closeConnAlarm);
-        return msg;
+        return new Msg(body, MsgType.closeConnAlarm);
     }
 
-    public static Msg readOneMsg(BufferedInputStream is) throws Exception {
+    public static Msg readOneMsg(BufferedInputStream is) throws IOException {
         byte[] inputB = new byte[9];
 
-        ByteArrayInputStream bais = null;
-        DataInputStream ois = null;
-
         Msg msg = new Msg();
-        try {
+        try( 
             DataInputStream dis = new DataInputStream(is);
+            ByteArrayInputStream bais = new ByteArrayInputStream(inputB);
+            DataInputStream ois = new DataInputStream(bais)){
             dis.readFully(inputB);
-            bais = new ByteArrayInputStream(inputB);
-            ois = new DataInputStream(bais);
-            short StartSign = ois.readShort();
-            if (StartSign != Msg.StartSign) {
+            short startSign = ois.readShort();
+            if (startSign != Msg.StartSign) {
                 throw new Exception("start sign is [" + Msg.StartSign
-                        + "],not is [" + StartSign + "]");
+                        + "],not is [" + startSign + "]");
             }
             int msgType = ois.readByte();
             msg.setMsgType(MsgType.getMsgTypeValue(msgType));
             dis.readFully(b);
             msg.newBodyfromBytes(b);
         } catch (Exception e) {
-            throw new Exception(e);
-        } finally {
-            if (bais != null) {
-                bais.close();
-            }
-            if (ois != null) {
-                ois.close();
-            }
-        }
+            throw new IOException("readOneMsg",e);
+        } 
 
         return msg;
     }
 
-    public static void writeMsg(Msg msg, BufferedOutputStream dout) throws Exception {
-
-        ByteArrayOutputStream byteOutStream = null;
-        DataOutputStream oos = null;
-        try {
-            byteOutStream = new ByteArrayOutputStream(9);
-            oos = new DataOutputStream(byteOutStream);
+    public static void writeMsg(Msg msg, BufferedOutputStream dout) throws IOException {
+        try( 
+            ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(9);
+            DataOutputStream oos = new DataOutputStream(byteOutStream)){
             oos.writeShort(Msg.StartSign);
             oos.writeByte(msg.getMsgType().value);
             oos.writeInt(Msg.creatMsgTimeStamp());
             dout.write(msg.getBodyBytes());
             dout.flush();
         } catch (Exception e) {
-            throw new Exception(e);
-        } finally {
-            if (oos != null) {
-                oos.close();
-            }
-            if (byteOutStream != null) {
-                byteOutStream.close();
-            }
-        }
+            throw new IOException("writeMsg",e);
+        } 
 
     }