数据挖掘DMS代码(JAVA).doc

上传人:自*** 文档编号:126225652 上传时间:2020-03-23 格式:DOC 页数:24 大小:71KB
返回 下载 相关 举报
数据挖掘DMS代码(JAVA).doc_第1页
第1页 / 共24页
数据挖掘DMS代码(JAVA).doc_第2页
第2页 / 共24页
数据挖掘DMS代码(JAVA).doc_第3页
第3页 / 共24页
数据挖掘DMS代码(JAVA).doc_第4页
第4页 / 共24页
数据挖掘DMS代码(JAVA).doc_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《数据挖掘DMS代码(JAVA).doc》由会员分享,可在线阅读,更多相关《数据挖掘DMS代码(JAVA).doc(24页珍藏版)》请在金锄头文库上搜索。

1、package com.tarena.dms;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PrintWriter;import java.io.RandomAcc

2、essFile;import .Socket;import java.util.ArrayList;import java.util.List;import java.util.Properties;import java.util.Scanner;import javax.swing.JFrame;public class DMSClient private DMSClientFrame frame;/* * 用于保存日志文件读取位置 */private File positionFile;/* * 用readLogs生成的文本日志文件 */private File textLogFile;

3、/* * 原始的unix日志文件 */private File logFile;public static final int LOG_LENGTH=372;public static final short LOGIN = 7;public static final short LOGOUT =8;private Properties config;private int batch;private File matchedLogFile;private File loginFile;private String serverHost;private int serverPort;/* *

4、利用构造器初始化对象属性 */public DMSClient() /读取配置文件,利用配置文件初始化参数对象config=new Properties();try config.load(new FileInputStream(client.properties); catch (IOException e) e.printStackTrace();throw new RuntimeException(e);logFile = new File(config.getProperty(log.file);positionFile=new File(config.getProperty(posi

5、tion.file);textLogFile=new File(config.getProperty(text.log.file);batch=Integer.parseInt(config.getProperty(batch);matchedLogFile=new File(config.getProperty(matched.log.file);loginFile=new File(config.getProperty(login.log.file);serverHost=config.getProperty(server.ip);serverPort=Integer.parseInt(c

6、onfig.getProperty(server.port);public void showReadLogsMsg(String msg)if(frame=null)System.out.println(msg);elseframe.showReadLogsMsg(msg);/* * 读取日志文件 */public void readLogs()/要保证在调用readLog()时logFile变量要有适用的对象if(!logFile.exists()showReadLogsMsg(没有unix日志文件!);return;if(textLogFile.exists()showReadLogsM

7、sg( 文本文件存在!本次不读取了!);return;/读取上回位置判断是否有新记录产生int n=0;/上次读取的记录号Scanner in=null; if(positionFile.exists() try in=new Scanner(positionFile);n=in.nextInt();showReadLogsMsg(读取本次记录号+n); catch (IOException e) e.printStackTrace();showReadLogsMsg(没有读取位置文件,从0读取。);n=0;finallyif(in!=null)in.close(); /检查是否有新记录产生

8、if(n*LOG_LENGTH=logFile.length() showReadLogsMsg(没有新记录产生!); return; /数据检查结束 /日志读取:从当前记录n开始,每次读取一批数据到log.txt /批次:每批次10个(最大) /打开输入文件RandomAccessFile /打开输出文件PrintWriter先创建一个临时文件作为输出文件,等文件用完后再改名为log.txt /使用循环从输入文件读取数据,写出输出文件 /int batch=10; RandomAccessFile raf=null; PrintWriter out=null; /临时文件,使用系统时间作文件

9、名 File temp=new File(System.currentTimeMillis()+.txt); showReadLogsMsg(使用临时文件+temp); try raf=new RandomAccessFile(logFile,r);showReadLogsMsg(打开文件+logFile);showReadLogsMsg(文件长度:+raf.length();/输出目标是临时文件out=new PrintWriter(temp);showReadLogsMsg(打开临时文件+temp);int i;/利用i得到下回读取的起始位置/for循环读取10条记录或到文件末尾就结束fo

10、r(i=0;ibatch;i+)/假设n=10,batch=10/i=10,11.19int n1=n+i;showReadLogsMsg(偏移量:+raf.getFilePointer();if(raf.getFilePointer()=(raf.length()-1)break;String log=readLog(raf,n1);if(log=null)break;showReadLogsMsg(读取日志+n1+:+log);out.println(log);showReadLogsMsg(写出日志+log);/记录最后读取位置n=n+i;PrintWriter w=new PrintW

11、riter(positionFile);w.println(n);showReadLogsMsg(保存下次读取记录号:+n);w.close(); catch (Exception e) e.printStackTrace();finallytry if(raf!=null)raf.close();if(out!=null)out.close(); catch (IOException e) e.printStackTrace();showReadLogsMsg(关闭文件);/将临时文件改名 if(!temp.renameTo(textLogFile) showReadLogsMsg(临时文件

12、改名失败!); showReadLogsMsg(临时文件改名为log.txt); public void showMatchLogs(String msg)if(frame=null)System.out.println(msg);elseframe.showMatchLogsMsg(msg);public void matchLogs()showMatchLogs(开始匹配日志数据);if(!textLogFile.exists()showMatchLogs(没有找到输入数据:+textLogFile);return;if(matchedLogFile.exists()showMatchLogs(匹配数据存在,+matchedLogFile+发送后才能继续匹配);return;List logs=new ArrayList();List logins=new ArrayList();List matched=new ArrayList();try readLogs(textLogFile,logs);/读取log.txtreadLogs(loginFile,logs);/读取login.txtshowMatchLogs(读取文件:+textLogFile+,+loginFile); catch (Exception e) showError(

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号