⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.java

📁 一个用于监控WEB服务器和数据库服务器的客户端程序。
💻 JAVA
字号:
/**
 * <p>Title: 卓博营运支撑系统</p>
 *
 * <p>Description: 为本企业内部运作提供支撑,为企业資源的E化管理提供解決方案</p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: 卓博信息科技有限公司</p>
 *
 * @author Henry
 * @version 1.0
 */
package com.jobcn.control;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;

/**  Common.java
 *   function: 
 *   describe:
 */
public final class Common {
	
	public static String getDateString(Date date){
		format = new SimpleDateFormat(defaultPattern); 
		return format.format(date);
	}
	
	public static String getDateString(Date date, String pattern){
		format = new SimpleDateFormat(pattern); 
		return format.format(date);
	}
	
	public static String getherHtmlCode(String urlStr) throws IOException {
		StringBuilder result = new StringBuilder();
		URL url = new URL(urlStr);
		HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
		urlConn.setConnectTimeout(5000);
		urlConn.connect();
		InputStream inputStream = urlConn.getInputStream();
		BufferedReader buffer = new BufferedReader(new InputStreamReader(
				inputStream));
		String temp;
		while ((temp = buffer.readLine()) != null) {
			result.append(temp+"\r\n");
		}
		urlConn.disconnect();
		inputStream.close();
		buffer.close();
		return result.toString();
	}

	public static void writeLog(
			String taskListName, int taskID, String outputStr, boolean isNormal){
		String startTag, endTag;
		if (isNormal) {
			startTag = "<normal filename=\""+taskListName+"\" taskID=\""+taskID+"\">";
			endTag = "</normal>\r\n";
		}
		else {
			startTag = "<error filename=\""+taskListName+"\" taskID=\""+taskID+"\">";
			endTag = "</error>\r\n";
		}
		outputStr = startTag + outputStr + endTag;
		String finalStr = "</log>";
		try {
			RandomAccessFile rf = new RandomAccessFile(Constant.logPath, "rw"); 
			if (!new File(Constant.logPath).exists()) {
				rf.write((Constant.logInitText).getBytes());
			}
			rf.seek(rf.length()-finalStr.length());
			rf.write((outputStr+finalStr).getBytes());
			rf.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void xmlParser(String xmlFile) {
		
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		StringBuilder sb = new StringBuilder();
		String htmCode = "", temp;
		String url = "http://192.168.60.216/BOSS_test/t.htm";
		try {
			htmCode = Common.getherHtmlCode(url);
			/*BufferedReader br = new BufferedReader(new FileReader("./html/dddd.htm"));
			while((temp = br.readLine()) != null) {
				sb.append(temp);
			}
			htmCode = sb.toString();
			br.close();*/
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		MessageCenter.sendSimpleEmail(
				new String[]{"daibing@jobcn.com"}, htmCode, "测试");

	}

	private static SimpleDateFormat format;
	private static String defaultPattern = "yyyy-MM-dd HH:mm:ss";
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -