if (Constant.COLLECT_TYPE_CM.equalsIgnoreCase(collectVo.getType())) {
parseResult = processCMXml(tempfile, nename, "CM");
} else {
- if (unfileName.indexOf(".csv") > 0) {
+ if (unfileName.indexOf(".csv") > -1) {//changed to -1 for coding practice as having ".csv" must have some some legal name
parseResult = processPMCsv(tempfile);
} else {
parseResult = processPMXml(tempfile);
try {
this.ftpClient.setSoTimeout(timeout);
} catch (Exception e) {
- //e.printStackTrace();
log.error(" StackTrace :", e);
}
}
ftpClient.logout();
ftpClient.disconnect();
} catch (Exception e) {
+ log.error(" StackTrace :", e);
}
ftpClient = null;
}
public boolean downloadFile(String remoteFile, String localFile) {
boolean sucess = false;
- BufferedOutputStream toLfileOutput = null;
- try {
- toLfileOutput = new BufferedOutputStream(new FileOutputStream(localFile));
+ try (
+ BufferedOutputStream toLfileOutput = new BufferedOutputStream(new FileOutputStream(localFile))){
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
if (ftpClient.retrieveFile(remoteFile, toLfileOutput)) {
sucess = true;
} catch (Exception ioe) {
sucess = false;
log.error("downloadFile remoteFile =" + remoteFile + " is fail ", ioe);
- } finally {
- if (toLfileOutput != null)
- try {
- toLfileOutput.close();
- } catch (IOException e) {
- }
- }
+ }
return sucess;
}
return returnValue;
}
-// public boolean store(String localFile, String remoteFile) {
-//
-// boolean sucess = false;
-// FileInputStream lfileInput = null;
-// try {
-// lfileInput = new FileInputStream(localFile);
-// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
-//
-// if (ftpClient.storeFile(remoteFile, lfileInput)){
-// sucess = true;
-// }else{
-// sucess = false;
-// }
-// } catch (Exception ioe) {
-// sucess = false;
-// log.error("store localFile = "+localFile+" is fail "+StringUtil.getStackTrace(ioe));
-// } finally {
-// if (lfileInput != null)
-// try {
-// lfileInput.close();
-// } catch (IOException e) {
-// }
-// }
-// return sucess;
-// }
-
}
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
public class StringUtil {
+ private static final Log log = LogFactory.getLog(StringUtil.class);
public static String getStackTrace(Throwable t) {
- StringWriter sw = null;
- PrintWriter pw = null;
- try {
- sw = new StringWriter();
- pw = new PrintWriter(sw);
+ try(
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw)){
t.printStackTrace(pw);
pw.flush();
sw.flush();
return sw.getBuffer().toString();
} catch (Exception e) {
-
- } finally {
- try {
- if (pw != null) pw.close();
- if (sw != null) sw.close();
- } catch (Exception e2) {
-
- }
- }
+ log.error("getStackTrace : ",e);
+ }
return null;
}
*
*/
public void deCompress() throws IOException {
- ZipFile zipFile = new ZipFile(zipFilePath);
- try {
+ try(ZipFile zipFile = new ZipFile(zipFilePath)){
Enumeration<ZipEntry> e = zipFile.getEntries();
for (ZipEntry entry; e.hasMoreElements(); ) {
entry = e.nextElement();
}
} catch (IOException e) {
throw e;
- } finally {
- zipFile.close();
- }
- }
+ }
+ }
/**
*
@Override
public void dispose() {
- //this.log.debug("start loading " + cacheFilePath);
File file = new File(CONFIG_PROPERTIES_LOCATION);
if (!file.exists() || !file.isFile()) {
log.error("cacheFilePath " + CONFIG_PROPERTIES_LOCATION + " not exist or is not File");
return;
}
- InputStream in = null;
- try {
+ try(InputStream in = new FileInputStream(file)){
properties = new Properties();
- in = new FileInputStream(file);
properties.load(in);
Map<String, CrontabVo> emsMap = readCorntab();
new ReceiveSource().start();
} catch (Exception e) {
log.error("read [" + file.getAbsolutePath() + "]Exception :", e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (Exception e) {
- }
- }
- }
+ }
}
public Map<String, CrontabVo> readCorntab() {
log.debug("not exists " + path);
return null;
}
- InputStream is = null;
Map<String, CrontabVo> tmpcache = new HashMap<String, CrontabVo>();
- try {
- is = new FileInputStream(cfg);
+ try (
+ InputStream is = new FileInputStream(cfg)){
Document doc = XmlUtil.getDocument(is);
Element root = doc.getRootElement();
} catch (Exception e) {
log.error("load crontab.xml is error " + StringUtil.getStackTrace(e));
- } finally {
- try {
- if (is != null) {
- is.close();
- is = null;
- }
- } catch (Exception e2) {
- }
- cfg = null;
- }
+ }
return tmpcache;
}
emsInfoCache.putAll(emsInfoMap);
}
if (emsInfoCache.size() > 0) {
- Thread.sleep(30 * 60 * 1000);
+ Thread.sleep(30 * 60 * 1000L);
} else {
- Thread.sleep(60 * 1000);
+ Thread.sleep(60 * 1000L);
}
} catch (Exception e) {
try {
- Thread.sleep(60 * 1000);
- } catch (InterruptedException e1) {
- //e1.printStackTrace();
+ Thread.sleep(60 * 1000L);
+ } catch (Exception e1) {
log.error("InterruptedException :" + StringUtil.getStackTrace(e1));
}
log.error("ReceiveSource exception", e);
public class MessageChannelFactory {
- public static Map<String, MessageChannel> map = new HashMap<String, MessageChannel>();
+ private static Map<String, MessageChannel> map = new HashMap<String, MessageChannel>();
public synchronized static MessageChannel getMessageChannel(String key, Integer size) {
if (map.get(key) != null) {
AgentMain.evel_post_event(header);
log.info("HeatBeat send!");
try {
- Thread.sleep(60000);//60 secs
+ Thread.sleep(60 * 1000L);//60 secs
} catch (Exception e) {
// e.printStackTrace();
log.error("Unable to sleep the HB thread ", e);
try {
eventTimeD = format.parse(eventTime);
} catch (ParseException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
log.error("ParseException ", e);
}
flt.evel_start_epoch_set(eventTimeD.getTime());
sm.evel_reporting_entity_id_set(rmUID.substring(0, 9));//
String Dn = reMap.get("Dn");
if (Dn != null)
- sm.evel_reporting_entity_name_set(Dn.substring(0, Dn != null && Dn.indexOf(";") > 0 ? Dn.indexOf(";") : Dn.length()));
+ sm.evel_reporting_entity_name_set(Dn.substring(0, Dn.indexOf(";") > -1 ? Dn.indexOf(";") : Dn.length()));//0 is valid index
else {
// decide the flow if Dn is null