浏览 1510 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-04-09
public class BillingInforByLogImpl implements BillingInforManager { private Logger logger; private String billingLogPath; private BillingStringTransform billingStringTransform; private ExceptionFileWriter exceptionFileWriter; private static final int TIME_BASE = 1000; private static final int CALENDAR_MINUTE_SET = 12; private static final int CUT_MINUTE = -20; public BillingInfor queryBillingInfor( ChannelContraposeInfor channelContraposeInfor) throws IOException { PropertyConfigurator.configure("conf" + File.separator + "log4j.properties"); logger = Logger.getRootLogger(); String fileName = getFileName(channelContraposeInfor.getIp(), channelContraposeInfor.getInOid()); logger.info("Read log is " + fileName); File file = new File(fileName); FileInputStream fileInputStream; try { fileInputStream = new FileInputStream(file); } catch (FileNotFoundException e) { writExceptionFile(channelContraposeInfor, " ", e.getMessage()); logger .error("BillingInforByLogImpl.queryBillingInfor|Can't find log file :" + fileName); throw new IOException(e.getMessage()); } return queryBillingInforFromLogFile(channelContraposeInfor, fileInputStream); } private void writExceptionFile( ChannelContraposeInfor channelContraposeInfor, String billingResult, String errorFlag) throws IOException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmm"); exceptionFileWriter.appendExceptionFile(channelContraposeInfor, simpleDateFormat.format(new Date()), billingResult, errorFlag); } private BillingInfor queryBillingInforFromLogFile( ChannelContraposeInfor channelContraposeInfor, FileInputStream fileInputStream) throws IOException { BufferedReader allFileLines = new BufferedReader(new InputStreamReader( fileInputStream)); try { String oneLine; while ((oneLine = allFileLines.readLine()) != null) { if (oneLine != null) { String[] oneLineStrings = oneLine.split(" "); if (oneLineStrings.length != 5 || !isNowTimeAddTenMinutesAfterFileTime(oneLineStrings[0])) { continue; } logger.info("File fist line is: " + oneLine); return billingStringTransform.transformBillingString( channelContraposeInfor.getChannelID(), oneLineStrings[1], oneLineStrings[2],oneLineStrings[0]); } } } catch (Exception e) { logger .error("BillingInforByLogImpl.queryBillingInfor|Analyse log file error :" + e.getMessage()); writExceptionFile(channelContraposeInfor, " ", e.getMessage()); throw new IOException(e.getMessage()); } writExceptionFile(channelContraposeInfor, " ", "Log file is no hava log infor"); throw new IOException( "BillingInforByLogImpl.queryBillingInfor|Log file is no hava log infor"); } private boolean isNowTimeAddTenMinutesAfterFileTime(String time) { GregorianCalendar fileTime = new GregorianCalendar(); GregorianCalendar thisTime = new GregorianCalendar(); Date date = new Date(Long.valueOf(time) * TIME_BASE); thisTime.setTime(new Date()); fileTime.setTime(date); thisTime.add(CALENDAR_MINUTE_SET, CUT_MINUTE); if (thisTime.after(fileTime)) { return true; } return false; } private String getFileName(String ip, String oid) { String[] flag = oid.split("\\."); return billingLogPath + File.separator + ip + "_" + flag[10] + ".old"; } public void setBillingLogPath(String billingLogPath) { this.billingLogPath = billingLogPath; } public void setBillingStringTransform( BillingStringTransform billingStringTransform) { this.billingStringTransform = billingStringTransform; } public void setExceptionFileWriter(ExceptionFileWriter exceptionFileWriter) { this.exceptionFileWriter = exceptionFileWriter; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-04-09
感觉需求不明确啊,问个 问题:
这个设定时间的方法,什么作用,设定的时间怎么用? |
|
返回顶楼 | |