From 9e193a366143bd6ef0423170eac76e6ef2689dbd Mon Sep 17 00:00:00 2001
From: yinzn
Date: Fri, 22 May 2020 11:23:56 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
yin-control/WebRoot/index.jsp | 291 ++++++++---------
yin-control/pom.xml | 26 +-
.../java/com/yin/common/util/ConfigUtil.java | 34 +-
.../java/com/yin/common/util/DateUtil.java | 67 ----
.../java/com/yin/common/util/MD5Util.java | 103 ------
.../yin/ycontrol/client/sms/SmsClient.java | 50 ---
.../ycontrol/client/sms/SmsHessianProxy.java | 80 -----
.../client/sms/SmsHessianProxyFactory.java | 50 ---
.../ycontrol/listener/ContextListener.java | 95 +++---
.../screenShotter/ControlServlet.java | 112 +++----
.../yin/ycontrol/screenShotter/Controler.java | 172 +++++-----
.../ycontrol/screenShotter/GifExample.java | 94 +++---
.../yin/ycontrol/screenShotter/GuiCamera.java | 236 +++++++-------
.../ycontrol/screenShotter/ImageServlet.java | 146 ++++-----
.../yin/ycontrol/screenShotter/ImageUtil.java | 302 +++++++++---------
.../ycontrol/screenShotter/VedioServlet.java | 118 +++----
.../com/yin/ycontrol/task/SendEmailTask.java | 40 ---
.../com/yin/ycontrol/task/UpdateMacTask.java | 60 ++--
.../java/com/yin/ycontrol/util/MailUtils.java | 266 ---------------
.../java/com/yin/ycontrol/util/NetUtil.java | 32 +-
.../com/yin/ycontrol/util/RegistryUtil.java | 50 ---
.../java/com/yin/ycontrol/util/SmsUtil.java | 13 -
.../java/com/yin/ycontrol/util/UrlUtil.java | 58 ----
.../src/main/java/jetty/JettyServer.java | 144 ++++-----
.../{ => main}/resources/config.properties | 0
25 files changed, 919 insertions(+), 1720 deletions(-)
delete mode 100644 yin-control/src/main/java/com/yin/common/util/DateUtil.java
delete mode 100644 yin-control/src/main/java/com/yin/common/util/MD5Util.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsClient.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxy.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxyFactory.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/task/SendEmailTask.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/util/MailUtils.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/util/RegistryUtil.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/util/SmsUtil.java
delete mode 100644 yin-control/src/main/java/com/yin/ycontrol/util/UrlUtil.java
rename yin-control/src/{ => main}/resources/config.properties (100%)
diff --git a/yin-control/WebRoot/index.jsp b/yin-control/WebRoot/index.jsp
index 0c5dd0e..33f31ba 100644
--- a/yin-control/WebRoot/index.jsp
+++ b/yin-control/WebRoot/index.jsp
@@ -1,154 +1,157 @@
-<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
-<%@page import="com.yin.ycontrol.screenShotter.GuiCamera"%>
+<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
+<%@page import="com.yin.ycontrol.screenShotter.GuiCamera" %>
<%
-String path = request.getContextPath();
-String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
+ String path = request.getContextPath();
+ String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
-
-
- 监控-支持HTML5的浏览器
-
-
-
-
-
-
-
-
-
-
+
+
+ 监控-支持HTML5的浏览器
+
+
+
+
+
+
+
+
+
+
diff --git a/yin-control/pom.xml b/yin-control/pom.xml
index 2f47be9..f41afec 100644
--- a/yin-control/pom.xml
+++ b/yin-control/pom.xml
@@ -12,6 +12,9 @@
UTF-8
+ 6
+ 6
+ 6
@@ -22,39 +25,24 @@
test
- repository.javax.mail
- mail
- 1.4
-
-
- repository.org.eclipse.jetty
+ org.eclipse.jetty
jetty-server
8.1.0.RC1
- repository.org.eclipse.jetty
+ org.eclipse.jetty
jetty-webapp
8.1.0.RC1
- repository.javax.servlet.jsp
+ javax.servlet.jsp
jsp-api
2.1
- repository.org.glassfish.web
+ org.glassfish.web
jsp-impl
2.2
-
- com.greenline.message
- greenline-message-service-share
- 1.2
-
-
- repository.com.caucho
- hessian
- 4.0.7
-
diff --git a/yin-control/src/main/java/com/yin/common/util/ConfigUtil.java b/yin-control/src/main/java/com/yin/common/util/ConfigUtil.java
index 3c6e2c5..6f70c24 100644
--- a/yin-control/src/main/java/com/yin/common/util/ConfigUtil.java
+++ b/yin-control/src/main/java/com/yin/common/util/ConfigUtil.java
@@ -5,23 +5,23 @@
public final class ConfigUtil {
- static Properties p = null;
+ static Properties p = null;
- static void init() {
- try {
- InputStream in = ConfigUtil.class.getClassLoader()
- .getResourceAsStream("config.properties");
- p = new Properties();
- p.load(in);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- public static String get(String key){
- if(p==null){
- init();
- }
- return p.getProperty(key);
+ static void init() {
+ try {
+ InputStream in = ConfigUtil.class.getClassLoader()
+ .getResourceAsStream("config.properties");
+ p = new Properties();
+ p.load(in);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ }
+ public static String get(String key){
+ if(p==null){
+ init();
+ }
+ return p.getProperty(key);
- }
+ }
}
diff --git a/yin-control/src/main/java/com/yin/common/util/DateUtil.java b/yin-control/src/main/java/com/yin/common/util/DateUtil.java
deleted file mode 100644
index ebb5cc1..0000000
--- a/yin-control/src/main/java/com/yin/common/util/DateUtil.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.yin.common.util;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * @Type DateUtil
- * @Desc
- * @author hongxia.huhx
- * @date 2012-3-4
- * @Version V1.0
- */
-public class DateUtil {
-
- /**
- * @Title: getDateString
- * @Description: ʹ"yyyy-MM-dd HH:mm:ss"ʽ
- * @author Yanjh
- * @param date
- * @return String
- */
- public static String getDateString(Date date) {
- return getDateString(date, "yyyy-MM-dd HH:mm:ss");
- }
-
- public static String getDateDay(Date date) {
- return getDateString(date, "yyyy-MM-dd");
- }
-
- /**
- * @Title: getDateString
- * @Description: ʽ
- * @author Yanjh
- * @param date
- * @param format ģʽ
- * @return String
- */
- public static String getDateString(Date date, String format) {
- if (date != null) {
- SimpleDateFormat formatter = new SimpleDateFormat(format);
- String dateString = formatter.format(date);
- return dateString;
- }
- return null;
- }
-
- /**
- * yyyy-MM-ddʽʱתdate
- *
- * @param strDate
- * @return
- */
- public static Date getDatebyString(String strDate) {
- if (null != strDate && !"".equals(strDate)) {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- try {
- return formatter.parse(strDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- return null;
-
- }
-
-}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/common/util/MD5Util.java b/yin-control/src/main/java/com/yin/common/util/MD5Util.java
deleted file mode 100644
index 5789eca..0000000
--- a/yin-control/src/main/java/com/yin/common/util/MD5Util.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package com.yin.common.util;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-
-/**
- * @Type MD5Util
- * @Desc MD5
- * @author hongxia.huhx
- * @date 2012-3-4
- * @Version V1.0
- */
-public class MD5Util {
-
- private static ThreadLocal messageDigestHolder = new ThreadLocal();
-
- // ֽת 16 Ʊʾַ
- static final char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
-
- static {
- try {
- MessageDigest message = java.security.MessageDigest.getInstance("MD5");
- messageDigestHolder.set(message);
- } catch (NoSuchAlgorithmException e) {
- }
- }
-
- /***
- *
- * @Title: getMD5Format
- * @Description: MD5תΪ32ֽʾ
- * @author wujl
- * @param data
- * @return String
- */
- public static String getMD5Format(String data) {
- try {
- MessageDigest message = messageDigestHolder.get();
- if (message == null) {
- message = java.security.MessageDigest.getInstance("MD5");
- messageDigestHolder.set(message);
- }
- message.update(data.getBytes("UTF-8"));
- byte[] b = message.digest();
-
- String digestHexStr = "";
- for (int i = 0; i < 16; i++) {
- digestHexStr += byteHEX(b[i]);
- }
-
- return digestHexStr;
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * MD5תΪ32ֽʾ
- * @param data
- * @return
- */
- public static String getMD5Format(String[] data) {
- try {
- MessageDigest message = messageDigestHolder.get();
- if (message == null) {
- message = java.security.MessageDigest.getInstance("MD5");
- messageDigestHolder.set(message);
- }
- for (int i = 0; i < data.length; i++) {
- message.update(data[i].getBytes("UTF-8"));
- }
- byte[] b = message.digest();
-
- String digestHexStr = "";
- for (int i = 0; i < 16; i++) {
- digestHexStr += byteHEX(b[i]);
- }
-
- return digestHexStr;
- } catch (Exception e) {
- return null;
- }
- }
-
-
-
- /***
- *
- * @Title: byteHEX
- * @Description:
- * @author wujl
- * @param ib
- * @return String
- */
- private static String byteHEX(byte ib) {
- char[] ob = new char[2];
- ob[0] = hexDigits[(ib >>> 4) & 0X0F];
- ob[1] = hexDigits[ib & 0X0F];
- String s = new String(ob);
- return s;
- }
-}
diff --git a/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsClient.java b/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsClient.java
deleted file mode 100644
index 79ac8a9..0000000
--- a/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsClient.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.yin.ycontrol.client.sms;
-
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.Properties;
-
-import com.greenline.message.biz.service.share.sms.SMSParamDTO;
-import com.greenline.message.biz.service.share.sms.SMSResultDTO;
-import com.greenline.message.biz.service.share.sms.SmsService;
-import com.yin.common.util.ConfigUtil;
-
-
-
-/**
- * @Type TestHessian
- * @Desc
- * @author john
- * @date 2012-4-26
- * @Version V1.0
- */
-public class SmsClient {
- static SmsService service;
- static Properties p;
- static {
- try {
- InputStream in = ConfigUtil.class.getClassLoader()
- .getResourceAsStream("sms.properties");
- p = new Properties();
- p.load(in);
-
- String url = p.getProperty("url");
- SmsHessianProxyFactory proxy = new SmsHessianProxyFactory();
- proxy.setClientid(p.getProperty("clientId"));
- proxy.setPassword(p.getProperty("password"));
- proxy.setCaller("95169");
-
- service = (SmsService) proxy.create(SmsService.class, url,ClassLoader.getSystemClassLoader());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void send(String mobile,String message) {
- SMSParamDTO param = new SMSParamDTO(mobile, message);
- SMSResultDTO ret = service.send(param);
- if(!ret.isSuccess()){
- System.out.println("##############Ͷų"+ret.getMessage());
- }
- }
-
-}
diff --git a/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxy.java b/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxy.java
deleted file mode 100644
index 2561b4b..0000000
--- a/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxy.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package com.yin.ycontrol.client.sms;
-
-import java.net.URL;
-import java.util.Date;
-
-import com.caucho.hessian.client.HessianConnection;
-import com.caucho.hessian.client.HessianProxy;
-import com.caucho.hessian.client.HessianProxyFactory;
-import com.yin.common.util.DateUtil;
-import com.yin.common.util.MD5Util;
-
-public class SmsHessianProxy extends HessianProxy {
- private String clientid;
- private String password;
- private String caller;
-
- private static final long serialVersionUID = -5745806908150418780L;
-
- /**
- * @param url
- * @param factory
- */
- protected SmsHessianProxy(URL url, HessianProxyFactory factory) {
- super(url, factory);
- }
-
- /**
- * Protected constructor for subclassing
- */
- protected SmsHessianProxy(URL url,
- HessianProxyFactory factory,
- Class> type)
- {
- super(url,factory,type);
- }
-
- /**
- * ùõͷ
- */
- @Override
- protected void addRequestHeaders(HessianConnection conn) {
- Date date = new Date();
- String requestseqnbr = DateUtil.getDateString(date, "yyyyMMddHHmmssMs");
- String requesttime = DateUtil.getDateString(date, "yyyyMMddHHmmssZ");
- String signdata = MD5Util.getMD5Format(clientid + requestseqnbr + requesttime + password);
-
- conn.addHeader("clientid",clientid);
- conn.addHeader("requestseqnbr",requestseqnbr);
- conn.addHeader("requesttime",requesttime);
- conn.addHeader("signdata",signdata);
- conn.addHeader("caller",caller);
-
- //hessianĴ
- super.addRequestHeaders(conn);
- }
-
- public String getClientid() {
- return clientid;
- }
-
- public void setClientid(String clientid) {
- this.clientid = clientid;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getCaller() {
- return caller;
- }
-
- public void setCaller(String caller) {
- this.caller = caller;
- }
-}
diff --git a/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxyFactory.java b/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxyFactory.java
deleted file mode 100644
index c8fc881..0000000
--- a/yin-control/src/main/java/com/yin/ycontrol/client/sms/SmsHessianProxyFactory.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.yin.ycontrol.client.sms;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.net.URL;
-
-import com.caucho.hessian.client.HessianProxyFactory;
-import com.caucho.hessian.io.HessianRemoteObject;
-
-public class SmsHessianProxyFactory extends HessianProxyFactory {
- private String clientid;
- private String password;
- private String caller;
-
- public String getClientid() {
- return clientid;
- }
-
- public void setClientid(String clientid) {
- this.clientid = clientid;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getCaller() {
- return caller;
- }
-
- public void setCaller(String caller) {
- this.caller = caller;
- }
-
- @Override
- public Object create(Class> api, URL url, ClassLoader loader) {
- if (api == null){
- throw new NullPointerException("api must not be null for HessianProxyFactory.create()");
- }
- SmsHessianProxy smsproxy = new SmsHessianProxy(url, this, api);
- smsproxy.setCaller(caller);
- smsproxy.setClientid(clientid);
- smsproxy.setPassword(password);
- InvocationHandler handler = smsproxy;
- return Proxy.newProxyInstance(loader, new Class[] { api, HessianRemoteObject.class }, handler);
- }
-}
diff --git a/yin-control/src/main/java/com/yin/ycontrol/listener/ContextListener.java b/yin-control/src/main/java/com/yin/ycontrol/listener/ContextListener.java
index d2c1d21..b0acee8 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/listener/ContextListener.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/listener/ContextListener.java
@@ -1,50 +1,47 @@
-package com.yin.ycontrol.listener;
-
-import java.util.Timer;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import com.yin.ycontrol.task.SendEmailTask;
-import com.yin.ycontrol.task.UpdateMacTask;
-
-
-public class ContextListener implements ServletContextListener {
- private Timer timer = null;
- private Timer mac_timer = null;
- /**
- * @contextDestroyed
- * @Ӧùرʱִд˷
- * @@param arg0
- * @throws
- */
- public void contextDestroyed(ServletContextEvent arg0) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * @contextInitialized
- * @Ӧʱִд˷
- * @@param event
- * @throws
- */
- public void contextInitialized(ServletContextEvent event) {
- try {
- timer = new Timer(true);
- event.getServletContext().log("ʱ");//־tomcat־в鿴
- timer.schedule(new SendEmailTask(event.getServletContext()),0,60*1000);
-// Thread.sleep(1000);
-// while(SendEmailTask.isRunning){
-// Thread.sleep(1000);
-// }
-// mac_timer = new Timer(true);
-// mac_timer.schedule(new UpdateMacTask(event.getServletContext()),0,23*60*60*1000);
-// event.getServletContext().log("Ѿ");
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- }
-
+package com.yin.ycontrol.listener;
+
+import java.util.Timer;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+
+public class ContextListener implements ServletContextListener {
+ private Timer timer = null;
+ private Timer mac_timer = null;
+ /**
+ * @方法名:contextDestroyed
+ * @功能描述:应用关闭时执行此方法
+ * @参数:@param arg0
+ * @throws
+ */
+ public void contextDestroyed(ServletContextEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @方法名:contextInitialized
+ * @功能描述:当应用启动时执行此方法
+ * @参数:@param event
+ * @throws
+ */
+ public void contextInitialized(ServletContextEvent event) {
+ try {
+ timer = new Timer(true);
+// event.getServletContext().log("定时器已启动");//添加日志,可在tomcat日志中查看到
+// timer.schedule(new SendEmailTask(event.getServletContext()),0,60*1000);
+// Thread.sleep(1000);
+// while(SendEmailTask.isRunning){
+// Thread.sleep(1000);
+// }
+// mac_timer = new Timer(true);
+// mac_timer.schedule(new UpdateMacTask(event.getServletContext()),0,23*60*60*1000);
+// event.getServletContext().log("已经添加任务");
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+
}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ControlServlet.java b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ControlServlet.java
index 1cb0775..3fab802 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ControlServlet.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ControlServlet.java
@@ -1,62 +1,52 @@
-package com.yin.ycontrol.screenShotter;
-
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.util.Random;
-
-import javax.imageio.ImageIO;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGEncodeParam;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
-
-public class ControlServlet extends HttpServlet {
- /**
- * ִе½ҵ
- * @param request:
- * @return destJspĿURL
- */
- public void service(HttpServletRequest request,
- HttpServletResponse response) throws IOException,ServletException{
- //ҳ治
- response.setHeader("Pragma", "No-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setDateHeader("Expires", 0);
- //ڴдͼ
-
- ServletOutputStream output;
- try {
- String x = request.getParameter("x");
- String y = request.getParameter("y");
- String e = request.getParameter("e");
- String k = request.getParameter("k");
- if(e==null){
-
- }else if(e.equalsIgnoreCase("mousedown")){
- Controler.mousedown(Integer.parseInt(x)-8, Integer.parseInt(y)-8);
- }else if(e.equalsIgnoreCase("mouseup")){
- Controler.mouseup(Integer.parseInt(x)-8, Integer.parseInt(y)-8);
- }else if(e.equalsIgnoreCase("rightclick")){
- Controler.rightClickPosition(Integer.parseInt(x)-8, Integer.parseInt(y)-8);
- }else if(e.equalsIgnoreCase("keydown")){
- Controler.keydown(Integer.parseInt(k));
- }else if(e.equalsIgnoreCase("keyup")){
- Controler.keyup(Integer.parseInt(k));
- }
- output = response.getOutputStream();
-
- output.flush();
- output.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+package com.yin.ycontrol.screenShotter;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class ControlServlet extends HttpServlet {
+ /**
+ * 执行登陆的业务处理
+ * @param request:发送上来的请求
+ * @return destJsp:目标URL
+ */
+ public void service(HttpServletRequest request,
+ HttpServletResponse response) throws IOException,ServletException{
+ //设置页面不缓存
+ response.setHeader("Pragma", "No-cache");
+ response.setHeader("Cache-Control", "no-cache");
+ response.setDateHeader("Expires", 0);
+ //在内存中创建图象
+
+ ServletOutputStream output;
+ try {
+ String x = request.getParameter("x");
+ String y = request.getParameter("y");
+ String e = request.getParameter("e");
+ String k = request.getParameter("k");
+ if(e==null){
+
+ }else if(e.equalsIgnoreCase("mousedown")){
+ Controler.mousedown(Integer.parseInt(x)-8, Integer.parseInt(y)-8);
+ }else if(e.equalsIgnoreCase("mouseup")){
+ Controler.mouseup(Integer.parseInt(x)-8, Integer.parseInt(y)-8);
+ }else if(e.equalsIgnoreCase("rightclick")){
+ Controler.rightClickPosition(Integer.parseInt(x)-8, Integer.parseInt(y)-8);
+ }else if(e.equalsIgnoreCase("keydown")){
+ Controler.keydown(Integer.parseInt(k));
+ }else if(e.equalsIgnoreCase("keyup")){
+ Controler.keyup(Integer.parseInt(k));
+ }
+ output = response.getOutputStream();
+
+ output.flush();
+ output.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/Controler.java b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/Controler.java
index ae3217c..35e8a8a 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/Controler.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/Controler.java
@@ -1,87 +1,87 @@
-package com.yin.ycontrol.screenShotter;
-
-import java.awt.AWTException;
-import java.awt.Robot;
-import java.awt.event.KeyEvent;
-/**
-* @author bean
-*
-*/
-public class Controler {
-
-private static Robot robot = null;
-
-static {
- try {
- robot = new Robot();
- } catch (AWTException e) {
- e.printStackTrace();
- }
-}
-/** ԵQQ */
-public void keyBoardDemo() {
- robot.keyPress(KeyEvent.VK_ALT);
- robot.keyPress(KeyEvent.VK_CONTROL);
- robot.keyPress(KeyEvent.VK_Z);
- robot.keyRelease(KeyEvent.VK_Z);
- robot.keyRelease(KeyEvent.VK_CONTROL);
- robot.keyRelease(KeyEvent.VK_ALT);
-}
-/** ǰиĴڣƶȻק600,600λ*/
- public void mouseDemo() {
- try {
- Thread.sleep(1000);
- robot.mousePress(KeyEvent.BUTTON3_MASK);
- robot.mouseRelease(KeyEvent.BUTTON3_MASK);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void mousedown(int x,int y) {
- try {
- robot.mouseMove(x, y);
- robot.mousePress(KeyEvent.BUTTON1_MASK);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void mouseup(int x,int y) {
- try {
- robot.mouseMove(x, y);
- robot.mouseRelease(KeyEvent.BUTTON1_MASK);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void rightClickPosition(int x,int y) {
- try {
- robot.mouseMove(x, y);
-
- robot.mousePress(KeyEvent.BUTTON3_MASK);
- robot.mouseRelease(KeyEvent.BUTTON3_MASK);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void keydown(int k) {
- if(k==13){
- k=KeyEvent.VK_ENTER;
- }
- robot.keyPress(k);
- }
- public static void keyup(int k) {
- if(k==13){
- k=KeyEvent.VK_ENTER;
- }
- robot.keyRelease(k);
- }
-/**
- * @param args
- */
-public static void main(String[] args) {
- //Controler demo=new Controler();
- rightClickPosition(10,10);
- //demo.mouseDemo();
-}
-
+package com.yin.ycontrol.screenShotter;
+
+import java.awt.AWTException;
+import java.awt.Robot;
+import java.awt.event.KeyEvent;
+/**
+ * @author bean
+ *
+ */
+public class Controler {
+
+ private static Robot robot = null;
+
+ static {
+ try {
+ robot = new Robot();
+ } catch (AWTException e) {
+ e.printStackTrace();
+ }
+ }
+ /** 可以弹出QQ */
+ public void keyBoardDemo() {
+ robot.keyPress(KeyEvent.VK_ALT);
+ robot.keyPress(KeyEvent.VK_CONTROL);
+ robot.keyPress(KeyEvent.VK_Z);
+ robot.keyRelease(KeyEvent.VK_Z);
+ robot.keyRelease(KeyEvent.VK_CONTROL);
+ robot.keyRelease(KeyEvent.VK_ALT);
+ }
+ /** 前提是有个最大化的窗口,功能是移动到标题栏,然后拖拽到600,600的位置*/
+ public void mouseDemo() {
+ try {
+ Thread.sleep(1000);
+ robot.mousePress(KeyEvent.BUTTON3_MASK);
+ robot.mouseRelease(KeyEvent.BUTTON3_MASK);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ public static void mousedown(int x,int y) {
+ try {
+ robot.mouseMove(x, y);
+ robot.mousePress(KeyEvent.BUTTON1_MASK);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ public static void mouseup(int x,int y) {
+ try {
+ robot.mouseMove(x, y);
+ robot.mouseRelease(KeyEvent.BUTTON1_MASK);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ public static void rightClickPosition(int x,int y) {
+ try {
+ robot.mouseMove(x, y);
+
+ robot.mousePress(KeyEvent.BUTTON3_MASK);
+ robot.mouseRelease(KeyEvent.BUTTON3_MASK);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ public static void keydown(int k) {
+ if(k==13){
+ k=KeyEvent.VK_ENTER;
+ }
+ robot.keyPress(k);
+ }
+ public static void keyup(int k) {
+ if(k==13){
+ k=KeyEvent.VK_ENTER;
+ }
+ robot.keyRelease(k);
+ }
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ //Controler demo=new Controler();
+ rightClickPosition(10,10);
+ //demo.mouseDemo();
+ }
+
}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GifExample.java b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GifExample.java
index 32b4d77..e30b312 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GifExample.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GifExample.java
@@ -1,48 +1,48 @@
-package com.yin.ycontrol.screenShotter;
-import java.awt.*;
-import java.awt.image.*;
-import java.io.*;
-import javax.imageio.*;
-
-/**
- * GIFͼ
- * @author Winter Lau (javayou@gmail.com)
- * @url http://www.oschina.net
- * @date 2009-8-10 09:58:16
- */
-public class GifExample {
- public static void main(String[] args) throws IOException {
- boolean ok = ImageIO.write(createImage(), "gif", new File("C://test.gif"));
- System.out.println("success=" + ok);
- }
-
- static BufferedImage createImage() {
- IndexColorModel cm = createIndexColorModel();;
- BufferedImage im = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_INDEXED, cm);
- Graphics2D g = im.createGraphics();
- g.setColor(new Color(0,0,0,0)); //transparent
- g.fillRect(0, 0, 100, 100);
- g.setColor(Color.RED);
- g.fillRect(0, 0, 50, 50);
- g.setColor(Color.GREEN);
- g.fillRect(50, 50, 50, 50);
- g.dispose();
- return im;
- }
-
- static IndexColorModel createIndexColorModel() {
- BufferedImage ex = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);
- IndexColorModel icm = (IndexColorModel) ex.getColorModel();
- int SIZE = 256;
- byte[] r = new byte[SIZE];
- byte[] g = new byte[SIZE];
- byte[] b = new byte[SIZE];
- byte[] a = new byte[SIZE];
- icm.getReds(r);
- icm.getGreens(g);
- icm.getBlues(b);
- java.util.Arrays.fill(a, (byte)255);
- r[0] = g[0] = b[0] = a[0] = 0; //transparent
- return new IndexColorModel(8, SIZE, r, g, b, a);
- }
+package com.yin.ycontrol.screenShotter;
+import java.awt.*;
+import java.awt.image.*;
+import java.io.*;
+import javax.imageio.*;
+
+/**
+ * 创建透明的GIF图像
+ * @author Winter Lau (javayou@gmail.com)
+ * @url http://www.oschina.net
+ * @date 2009-8-10 上午09:58:16
+ */
+public class GifExample {
+ public static void main(String[] args) throws IOException {
+ boolean ok = ImageIO.write(createImage(), "gif", new File("C://test.gif"));
+ System.out.println("success=" + ok);
+ }
+
+ static BufferedImage createImage() {
+ IndexColorModel cm = createIndexColorModel();;
+ BufferedImage im = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_INDEXED, cm);
+ Graphics2D g = im.createGraphics();
+ g.setColor(new Color(0,0,0,0)); //transparent
+ g.fillRect(0, 0, 100, 100);
+ g.setColor(Color.RED);
+ g.fillRect(0, 0, 50, 50);
+ g.setColor(Color.GREEN);
+ g.fillRect(50, 50, 50, 50);
+ g.dispose();
+ return im;
+ }
+
+ static IndexColorModel createIndexColorModel() {
+ BufferedImage ex = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);
+ IndexColorModel icm = (IndexColorModel) ex.getColorModel();
+ int SIZE = 256;
+ byte[] r = new byte[SIZE];
+ byte[] g = new byte[SIZE];
+ byte[] b = new byte[SIZE];
+ byte[] a = new byte[SIZE];
+ icm.getReds(r);
+ icm.getGreens(g);
+ icm.getBlues(b);
+ java.util.Arrays.fill(a, (byte)255);
+ r[0] = g[0] = b[0] = a[0] = 0; //transparent
+ return new IndexColorModel(8, SIZE, r, g, b, a);
+ }
}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GuiCamera.java b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GuiCamera.java
index 34889b5..1f1ed5a 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GuiCamera.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/GuiCamera.java
@@ -1,14 +1,14 @@
package com.yin.ycontrol.screenShotter;
import java.awt.Color;
-import java.awt.Dimension;
+import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.Robot;
-import java.awt.Toolkit;
-import java.awt.image.BufferedImage;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -22,146 +22,146 @@
import com.sun.image.codec.jpeg.JPEGImageEncoder;
/*******************************************************************
- * JavaBeanֱJavaӦóеãʵĻ""
+ * ��JavaBean����ֱ��������JavaӦ�ó����е��ã�ʵ����Ļ��"����"
* This JavaBean is used to snapshot the GUI in a
* Java application! You can embeded
* it in to your java application source code, and us
* it to snapshot the right GUI of the application
- *
+ *
*****************************************************/
-public class GuiCamera
-{
- private String fileName; //ļǰ
- private String defaultName = "GuiCamera";
- static int serialNum=0;
- private String imageFormat; //ͼļĸʽ
- private String defaultImageFormat="png";
+public class GuiCamera
+{
+ private String fileName; //�ļ���ǰ
+ private String defaultName = "GuiCamera";
+ static int serialNum=0;
+ private String imageFormat; //ͼ���ļ��ĸ�ʽ
+ private String defaultImageFormat="png";
static Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
static BufferedImage screenshot;
static Date lasttime=new Date(new Date().getTime()-10000);
/****************************************************************
- * ĬϵļǰΪGuiCameraļʽΪPNGʽ
+ * Ĭ�ϵ��ļ�ǰΪGuiCamera���ļ���ʽΪPNG��ʽ
* The default construct will use the default
* Image file surname "GuiCamera",
* and default image format "png"
- ****************************************************************/
- public GuiCamera() {
- fileName = defaultName;
- imageFormat=defaultImageFormat;
-
+ ****************************************************************/
+ public GuiCamera() {
+ fileName = defaultName;
+ imageFormat=defaultImageFormat;
+
}
/****************************************************************
* @param s the surname of the snapshot file
* @param format the format of the image file,
* it can be "jpg" or "png"
- * ֧JPGPNGļĴ洢
- ****************************************************************/
- public GuiCamera(String s,String format) {
-
- fileName = s;
- imageFormat=format;
- }
-
+ * ������֧��JPG��PNG�ļ��Ĵ洢
+ ****************************************************************/
+ public GuiCamera(String s,String format) {
+
+ fileName = s;
+ imageFormat=format;
+ }
+
/****************************************************************
- * Ļ
+ * ����Ļ��������
* snapShot the Gui once
- ****************************************************************/
- public void snapShot(BufferedImage screenshot,String format) {
-
- try {
- //ĻһBufferedImagescreenshot
- //ļǰļʽԶļ
- Date start=new Date();
- String name=fileName+String.valueOf(serialNum)+"."+format;
- File f = new File(name);
- OutputStream jos = new FileOutputStream( f );
- System.out.print("Save File "+name);
- JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( jos );
- JPEGEncodeParam jpegEP = JPEGCodec.getDefaultJPEGEncodeParam( screenshot );
- jpegEP.setQuality( (float) 0.1 , true );
- encoder.encode( screenshot , jpegEP );
-
- serialNum++;
-
-
-
- jos.flush();
- jos.close();
- //screenshotдͼļ
-
- //ImageIO.write(screenshot, format, f);
- Date end=new Date();
- System.out.print("..Finished! Cost "+(end.getTime()-start.getTime())+"\n");
- }
- catch (Exception ex) {
- ex.printStackTrace();
- System.out.println(ex);
- }
+ ****************************************************************/
+ public void snapShot(BufferedImage screenshot,String format) {
+
+ try {
+ //������Ļ��һ��BufferedImage����screenshot
+ //�����ļ�ǰ�������ļ���ʽ�������Զ������ļ���
+ Date start=new Date();
+ String name=fileName+String.valueOf(serialNum)+"."+format;
+ File f = new File(name);
+ OutputStream jos = new FileOutputStream( f );
+ System.out.print("Save File "+name);
+ JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( jos );
+ JPEGEncodeParam jpegEP = JPEGCodec.getDefaultJPEGEncodeParam( screenshot );
+ jpegEP.setQuality( (float) 0.1 , true );
+ encoder.encode( screenshot , jpegEP );
+
+ serialNum++;
+
+
+
+ jos.flush();
+ jos.close();
+ //��screenshot����д��ͼ���ļ�
+
+ //ImageIO.write(screenshot, format, f);
+ Date end=new Date();
+ System.out.print("..Finished! Cost "+(end.getTime()-start.getTime())+"\n");
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ System.out.println(ex);
+ }
+ }
+
+ public static BufferedImage screenShot() {
+
+ try {
+ Date now=new Date();
+ if(now.getTime()-lasttime.getTime()>100){
+ lasttime=now;
+ Robot robot =new Robot();
+ screenshot = robot
+ .createScreenCapture(new Rectangle(0, 0,
+ (int) d.getWidth(), (int) d.getHeight()));
+ //�������
+ //��ȡ���λ��
+ Point p=java.awt.MouseInfo.getPointerInfo().getLocation();
+ Graphics g = screenshot.getGraphics();
+ g.setColor(Color.red);
+ g.fillRoundRect(p.x-10, p.y-10, 20, 20,40,40);
+ g.dispose();
+ //ѹ��
+ screenshot=getConvertedImage(screenshot);
+ }
+ return screenshot;
+ } catch (Exception ex) {
+ System.out.println(ex);
+ BufferedImage error = new BufferedImage(100, 100,
+ BufferedImage.TYPE_INT_RGB);
+ // Get drawing context
+ Graphics g = error.getGraphics();
+ // Fill background
+ g.setColor(Color.blue);
+ g.drawString("��ȡ��Ļͼ�����", 10, 10);
+ g.dispose();
+ return error;
+ }
+
+ }
+ //ѹ��ͼ��
+ private static BufferedImage getConvertedImage(BufferedImage image){
+ int width=image.getWidth();
+ int height=image.getHeight();
+ BufferedImage convertedImage=null;
+ Graphics2D g2D=null;
+ //���ô�1 �ֽ�alpha��TYPE_4BYTE_ABGR�����������صIJ�����
+ convertedImage=new BufferedImage(width, height, BufferedImage.TYPE_USHORT_555_RGB);
+ g2D = (Graphics2D) convertedImage.getGraphics();
+ g2D.drawImage(image, 0, 0, null);
+ g2D.drawImage(convertedImage, 0, 0, null);
+ g2D.dispose();
+ return convertedImage;
}
- public static BufferedImage screenShot() {
-
- try {
- Date now=new Date();
- if(now.getTime()-lasttime.getTime()>100){
- lasttime=now;
- Robot robot =new Robot();
- screenshot = robot
- .createScreenCapture(new Rectangle(0, 0,
- (int) d.getWidth(), (int) d.getHeight()));
- //
- //ȡλ
- Point p=java.awt.MouseInfo.getPointerInfo().getLocation();
- Graphics g = screenshot.getGraphics();
- g.setColor(Color.red);
- g.fillRoundRect(p.x-10, p.y-10, 20, 20,40,40);
- g.dispose();
- //ѹ
- screenshot=getConvertedImage(screenshot);
- }
- return screenshot;
- } catch (Exception ex) {
- System.out.println(ex);
- BufferedImage error = new BufferedImage(100, 100,
- BufferedImage.TYPE_INT_RGB);
- // Get drawing context
- Graphics g = error.getGraphics();
- // Fill background
- g.setColor(Color.blue);
- g.drawString("ȡĻͼ", 10, 10);
- g.dispose();
- return error;
- }
-
- }
- //ѹͼ
- private static BufferedImage getConvertedImage(BufferedImage image){
- int width=image.getWidth();
- int height=image.getHeight();
- BufferedImage convertedImage=null;
- Graphics2D g2D=null;
- //ô1 ֽalphaTYPE_4BYTE_ABGRصIJ
- convertedImage=new BufferedImage(width, height, BufferedImage.TYPE_USHORT_555_RGB);
- g2D = (Graphics2D) convertedImage.getGraphics();
- g2D.drawImage(image, 0, 0, null);
- g2D.drawImage(convertedImage, 0, 0, null);
- g2D.dispose();
- return convertedImage;
- }
-
- public static void main(String[] args)
- {
+ public static void main(String[] args)
+ {
GuiCamera cam= new GuiCamera("d:\\111\\Hello", "png");//
- BufferedImage screenshot = screenShot();
- cam.snapShot(screenshot,"JPG");
- }
+ BufferedImage screenshot = screenShot();
+ cam.snapShot(screenshot,"JPG");
+ }
public static int getWidth(){
- return (int)d.getWidth();
+ return (int)d.getWidth();
}
public static int getHeight(){
- return (int)d.getHeight();
+ return (int)d.getHeight();
}
}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageServlet.java b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageServlet.java
index a077577..51a22e6 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageServlet.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageServlet.java
@@ -1,74 +1,74 @@
-package com.yin.ycontrol.screenShotter;
-
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Map;
-import java.util.HashMap;
-
-import javax.imageio.ImageIO;
-import javax.imageio.spi.ImageWriterSpi;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import sun.awt.image.PNGImageDecoder;
-
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGEncodeParam;
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
-import com.sun.imageio.plugins.png.PNGImageWriter;
-
-public class ImageServlet extends HttpServlet {
- /**
- *
- */
- private static final long serialVersionUID = -7241394871084993707L;
- /**
- * ִе½ҵ
- * @param request:
- * @return destJspĿURL
- */
- @Override
- public void service(HttpServletRequest request,
- HttpServletResponse response) throws IOException,ServletException{
- //ҳ治
- response.setHeader("Pragma", "No-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setDateHeader("Expires", 0);
- //ȡ֡
- if(request.getParameter("lastframe")!=null){
- response.getWriter().write(ImageUtil.getFrame()+"");
- response.getWriter().close();
- return;
- }
- //ȡͼƬ
- ServletOutputStream output;
- try {
- output = response.getOutputStream();
-
- Long min=0l;
- Long max=0l;
- try{
- String minStr=request.getParameter("min");
- String maxStr=request.getParameter("max");
- min=Long.parseLong(minStr);
- max=Long.parseLong(maxStr);
- }catch(Exception ex){}
- BufferedImage image = ImageUtil.getImage(min, max);
- //ImageIO.write(image, "gif", new File("C://test"+new Date().getTime()+".gif"));
- ImageIO.write(image, "gif", output);
- // ͼҳ
- output.flush();
- output.close();
- //ImageIO.write(image, "PNG", output);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
+package com.yin.ycontrol.screenShotter;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
+
+import javax.imageio.ImageIO;
+import javax.imageio.spi.ImageWriterSpi;
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import sun.awt.image.PNGImageDecoder;
+
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+import com.sun.imageio.plugins.png.PNGImageWriter;
+
+public class ImageServlet extends HttpServlet {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7241394871084993707L;
+ /**
+ * 执行登陆的业务处理
+ * @param request:发送上来的请求
+ * @return destJsp:目标URL
+ */
+ @Override
+ public void service(HttpServletRequest request,
+ HttpServletResponse response) throws IOException,ServletException{
+ //设置页面不缓存
+ response.setHeader("Pragma", "No-cache");
+ response.setHeader("Cache-Control", "no-cache");
+ response.setDateHeader("Expires", 0);
+ //获取最新帧数
+ if(request.getParameter("lastframe")!=null){
+ response.getWriter().write(ImageUtil.getFrame()+"");
+ response.getWriter().close();
+ return;
+ }
+ //获取图片
+ ServletOutputStream output;
+ try {
+ output = response.getOutputStream();
+
+ Long min=0l;
+ Long max=0l;
+ try{
+ String minStr=request.getParameter("min");
+ String maxStr=request.getParameter("max");
+ min=Long.parseLong(minStr);
+ max=Long.parseLong(maxStr);
+ }catch(Exception ex){}
+ BufferedImage image = ImageUtil.getImage(min, max);
+ //ImageIO.write(image, "gif", new File("C://test"+new Date().getTime()+".gif"));
+ ImageIO.write(image, "gif", output);
+ // 输出图象到页面
+ output.flush();
+ output.close();
+ //ImageIO.write(image, "PNG", output);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageUtil.java b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageUtil.java
index 25e5814..82aa8b4 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageUtil.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/screenShotter/ImageUtil.java
@@ -1,151 +1,151 @@
-package com.yin.ycontrol.screenShotter;
-
-import java.awt.AlphaComposite;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
-import java.awt.image.IndexColorModel;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-public class ImageUtil {
- private static final int CATCH_SIZE = 20;
- private static final int INTERVAL = 200;
- private static Long frame = 1L;
- static BufferedImage lastImage = null;
- static BufferedImage currentImage = null;
- private static Map imageCache = new HashMap();
- static Date last = null;
-
- /**
- *
- * @param min ͻһ֡ı
- * @param max ͻ˸ոջȡһ֡ı(ͼǰýӿڻȡ)
- * @return
- */
- public static BufferedImage getImage(Long min,Long max){
-
- Date now = new Date();
- //ʱINTERVALʱˢͼ(
- //ŵ:1ûʱ˲ԼˢѰͼ
- // 2ٶ,Ҳڴѹ,ҹͼƬԴ
- if(last==null||now.getTime()-last.getTime()>INTERVAL){
- currentImage = GuiCamera.screenShot();
- BufferedImage cache = ImageUtil.subImage(lastImage, currentImage);
- //仯
- if(lastImage!=null){
- catchImage(cache);
- }
- lastImage=currentImage;
- last=now;
- }
-
- //ȡҪͼ
- //ʱ,ͼ. ֻر仯IJ
- if(imageCache.get(min)==null){
- return currentImage;
- }else if(min>=max){//Ҳǿͻ)
- return empty();
- }else{
- return getImageCatch(min,max);
- }
- }
-
- private static void catchImage(BufferedImage image){
- if(frame>=9223372036854775806L){//ֹԽ
- frame=0L;
- imageCache=new HashMap();
- }
- imageCache.put(frame, image);
- if(imageCache.size()>CATCH_SIZE){
- imageCache.remove(new Long(frame-CATCH_SIZE));
- }
- frame+=1;
- }
- private static BufferedImage getImageCatch(Long min,Long max){
- BufferedImage result = null;
- for(Long i=min+1;i<=max;i++){
- result=drawCache(result,imageCache.get(i));
- }
- return result;
- }
-
- public static BufferedImage drawCache(BufferedImage image,BufferedImage cache){
- if(image==null){
- return cache;
- }
- int width = cache.getWidth();
- int height = cache.getHeight();
- for(int x=0;x imageCache = new HashMap();
+ static Date last = null;
+
+ /**
+ *
+ * @param min 客户端最后一帧的编号
+ * @param max 客户端刚刚获取的最新一帧的编号(在请求图像前调用接口获取)
+ * @return
+ */
+ public static BufferedImage getImage(Long min,Long max){
+
+ Date now = new Date();
+ //时间间隔大于INTERVAL时才刷新图像(
+ //优点:1没有请求时服务端不会自己刷寻图像
+ // 2请求数量再多,也不会造成内存压力,大家共享缓存图片资源
+ if(last==null||now.getTime()-last.getTime()>INTERVAL){
+ currentImage = GuiCamera.screenShot();
+ BufferedImage cache = ImageUtil.subImage(lastImage, currentImage);
+ //缓存变化部分
+ if(lastImage!=null){
+ catchImage(cache);
+ }
+ lastImage=currentImage;
+ last=now;
+ }
+
+ //获取需要的图像
+ //如果时间过长,返回整张图像. 否则只返回变化的不分
+ if(imageCache.get(min)==null){
+ return currentImage;
+ }else if(min>=max){//也许是客户端请求过快)
+ return empty();
+ }else{
+ return getImageCatch(min,max);
+ }
+ }
+
+ private static void catchImage(BufferedImage image){
+ if(frame>=9223372036854775806L){//防止越界
+ frame=0L;
+ imageCache=new HashMap();
+ }
+ imageCache.put(frame, image);
+ if(imageCache.size()>CATCH_SIZE){
+ imageCache.remove(new Long(frame-CATCH_SIZE));
+ }
+ frame+=1;
+ }
+ private static BufferedImage getImageCatch(Long min,Long max){
+ BufferedImage result = null;
+ for(Long i=min+1;i<=max;i++){
+ result=drawCache(result,imageCache.get(i));
+ }
+ return result;
+ }
+
+ public static BufferedImage drawCache(BufferedImage image,BufferedImage cache){
+ if(image==null){
+ return cache;
+ }
+ int width = cache.getWidth();
+ int height = cache.getHeight();
+ for(int x=0;x
- * Title: ʹjavamailʼ
- *
- */
-public class MailUtils {
-
- String to = "";// ռ
- String from = "";//
- String host = "";// smtp
- String username = "";
- String password = "";
- String filename = "";// ļ
- String subject = "";// ʼ
- String content = "";// ʼ
- Vector file = new Vector();// ļ
-
- /**
- *
- * ˵ĬϹ
- *
- * ͣ
- */
- public MailUtils() {
- }
-
- /**
- *
- * ˵ṩֱӵIJ
- *
- * ͣ
- */
- public MailUtils(String to, String from, String smtpServer,
- String username, String password, String subject, String content) {
- this.to = to;
- this.from = from;
- this.host = smtpServer;
- this.username = username;
- this.password = password;
- this.subject = subject;
- this.content = content;
- }
-
- /**
- *
- * ˵ʼַ
- * String host ʼַ
- * ͣ
- */
- public void setHost(String host) {
- this.host = host;
- }
-
- /**
- *
- * ˵õ¼У
- *
- * ͣ
- */
- public void setPassWord(String pwd) {
- this.password = pwd;
- }
-
- /**
- *
- * ˵õ¼Уû
- *
- * ͣ
- */
- public void setUserName(String usn) {
- this.username = usn;
- }
-
- /**
- *
- * ˵ʼĿ
- *
- * ͣ
- */
- public void setTo(String to) {
- this.to = to;
- }
-
- /**
- *
- * ˵ʼԴ
- *
- * ͣ
- */
- public void setFrom(String from) {
- this.from = from;
- }
-
- /**
- *
- * ˵ʼ
- *
- * ͣ
- */
- public void setSubject(String subject) {
- this.subject = subject;
- }
-
- /**
- *
- * ˵ʼ
- *
- * ͣ
- */
- public void setContent(String content) {
- this.content = content;
- }
-
- /**
- *
- * ˵תΪ
- * String strText
- * ͣ
- */
- public String transferChinese(String strText) {
- try {
- strText = MimeUtility.encodeText(new String(strText.getBytes(),
- "GB2312"), "GB2312", "B");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return strText;
- }
-
- /**
- *
- * ˵Ӹ
- *
- * ͣ
- */
- public void attachfile(String fname) {
- file.addElement(fname);
- }
-
- /**
- *
- * ˵ʼ
- *
- * ͣboolean ɹΪtrue֮Ϊfalse
- */
- public boolean sendMail() {
-
- // mail session
- Properties props = new Properties() ;
- if(this.host.indexOf("smtp.gmail.com")>=0)
- {
- props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
- props.setProperty("mail.smtp.socketFactory.fallback", "false");
- props.setProperty("mail.smtp.port", "465");
- props.setProperty("mail.smtp.socketFactory.port", "465");
- }
- props.put("mail.smtp.host", host);
- props.put("mail.smtp.auth", "true");
- Session session = Session.getDefaultInstance(props,
- new Authenticator() {
- public PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(username, password);
- }
- });
- //Session session = Session.getDefaultInstance(props);
-// Session session = Session.getDefaultInstance(props, null);
-
- try {
- // MimeMessage 趨ֵ
- MimeMessage msg = new MimeMessage(session);
- //MimeMessage msg = new MimeMessage();
- msg.setFrom(new InternetAddress(from));
-
-
- //msg.addRecipients(Message.RecipientType.TO, address); //ֻǸһ˷email
- msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(to)) ;
- subject = transferChinese(subject);
- msg.setSubject(subject);
-
- // Multipart
- Multipart mp = new MimeMultipart();
-
- // Multipart
- MimeBodyPart mbpContent = new MimeBodyPart();
- mbpContent.setContent(content, "text/html;charset=gb2312");
-
- // MimeMessageӣMultipartģ
- mp.addBodyPart(mbpContent);
-
- // MultipartӸ
- Enumeration efile = file.elements();
- while (efile.hasMoreElements()) {
-
- MimeBodyPart mbpFile = new MimeBodyPart();
- filename = efile.nextElement().toString();
- FileDataSource fds = new FileDataSource(filename);
- mbpFile.setDataHandler(new DataHandler(fds));
- //Խ⡣
- String filename= new String(fds.getName().getBytes(),"ISO-8859-1");
-
- mbpFile.setFileName(filename);
- // MimeMessageӣMultipart
- mp.addBodyPart(mbpFile);
-
- }
-
- file.removeAllElements();
- // MultipartMimeMessage
- msg.setContent(mp);
- msg.setSentDate(new Date());
- msg.saveChanges() ;
- // ʼ
-
- Transport transport = session.getTransport("smtp");
- transport.connect(host, username, password);
- transport.sendMessage(msg, msg.getAllRecipients());
- transport.close();
- } catch (Exception mex) {
- mex.printStackTrace();
- return false;
- }
- return true;
- }
-
-
-
- /**
- *
- */
- public static void send(String title,String content) {
- String email = ConfigUtil.get("email");
- if(email!=null&&email.length()>0){
- MailUtils sendmail = new MailUtils();
- sendmail.setHost("smtp.gmail.com");
- sendmail.setUserName("ycontrolservice");
- sendmail.setPassWord("123qweqwe");
- sendmail.setTo(email);
- sendmail.setFrom("ycontrolservice@gmail.com");
- sendmail.setSubject(title);
- sendmail.setContent(content);
- System.out.println(sendmail.sendMail());
- }
- }
-}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/util/NetUtil.java b/yin-control/src/main/java/com/yin/ycontrol/util/NetUtil.java
index ecf8073..0fbdd38 100644
--- a/yin-control/src/main/java/com/yin/ycontrol/util/NetUtil.java
+++ b/yin-control/src/main/java/com/yin/ycontrol/util/NetUtil.java
@@ -1,16 +1,16 @@
-package com.yin.ycontrol.util;
-
-public class NetUtil {
- public static void restartNet(){
- try{
- Runtime.getRuntime().exec("netsh interface set interface name=\"\" admin=DISABLED");
- Thread.sleep(20000);
- Runtime.getRuntime().exec("netsh interface set interface name=\"\" admin=ENABLED");
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- }
- public static void main(String[] args){
- restartNet();
- }
-}
+package com.yin.ycontrol.util;
+
+public class NetUtil {
+ public static void restartNet(){
+ try{
+ Runtime.getRuntime().exec("netsh interface set interface name=\"本地连接\" admin=DISABLED");
+ Thread.sleep(20000);
+ Runtime.getRuntime().exec("netsh interface set interface name=\"本地连接\" admin=ENABLED");
+ }catch(Exception e){
+ System.out.println(e.getMessage());
+ }
+ }
+ public static void main(String[] args){
+ restartNet();
+ }
+}
diff --git a/yin-control/src/main/java/com/yin/ycontrol/util/RegistryUtil.java b/yin-control/src/main/java/com/yin/ycontrol/util/RegistryUtil.java
deleted file mode 100644
index 46cc7ec..0000000
--- a/yin-control/src/main/java/com/yin/ycontrol/util/RegistryUtil.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.yin.ycontrol.util;
-
-import java.util.Enumeration;
-
-//import com.ice.jni.registry.*;
-
-public class RegistryUtil {
- /*public static void updateMac(){
- try{
- RegistryKey r = Registry.HKEY_LOCAL_MACHINE.
- openSubKey("SYSTEM\\ControlSet001\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}");
- String realRegName=null;
- Enumeration> enums = r.keyElements();
- while (enums.hasMoreElements()) {
- String childRKName = (String)enums.nextElement();
- RegistryKey childMac = r.openSubKey(childRKName);
- String driverDesc = null;
- try{
- driverDesc = childMac.getStringValue("DriverDesc");
- }catch(Exception ex){}
- if(driverDesc!=null&&driverDesc.indexOf("Realtek")>-1){
- realRegName=childRKName;
- break;
- }
- }
- RegistryKey macKey = r.openSubKey(realRegName);
- String v=macKey.getStringValue("NetworkAddress");
- String last4s=v.substring(8);
- int last4=1000;
- try{
- last4=Integer.parseInt(last4s);
- }catch(Exception ex){}
- last4++;
- RegistryKey subKey = r.createSubKey(realRegName, "");
-// if(v!=null) {
-// System.out.println(v.toString());//
-// }
- subKey.setValue(new RegStringValue(subKey, "NetworkAddress",
- "000C0F0F"+last4));
- subKey.closeKey();
-
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
- public static void main(String[] args){
- updateMac();
- }
- */
-}
\ No newline at end of file
diff --git a/yin-control/src/main/java/com/yin/ycontrol/util/SmsUtil.java b/yin-control/src/main/java/com/yin/ycontrol/util/SmsUtil.java
deleted file mode 100644
index 5f4b57c..0000000
--- a/yin-control/src/main/java/com/yin/ycontrol/util/SmsUtil.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.yin.ycontrol.util;
-
-import com.yin.common.util.ConfigUtil;
-import com.yin.ycontrol.client.sms.SmsClient;
-
-public class SmsUtil {
- public static void send(String message) {
- String mobile=ConfigUtil.get("mobile");
- if(mobile!=null&&mobile.length()>0){
- SmsClient.send(mobile, message);
- }
- }
-}
diff --git a/yin-control/src/main/java/com/yin/ycontrol/util/UrlUtil.java b/yin-control/src/main/java/com/yin/ycontrol/util/UrlUtil.java
deleted file mode 100644
index 5b6c9a7..0000000
--- a/yin-control/src/main/java/com/yin/ycontrol/util/UrlUtil.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.yin.ycontrol.util;
-
-import java.io.BufferedReader;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class UrlUtil {
- public static String getUrl() {
- InputStream in = null;
- OutputStream out = null;
- try {
- // в
- if (false)
- throw new IllegalArgumentException("Wrong number of args");
- // URL url = new URL("http://www.ip138.com/ip2city.asp"); // URL
- // õһ
- // URL url = new URL("http://202.105.81.135/showip/"); // URL
- //URL url = new URL("http://www.ip.cn/"); // URL
- URL url = new URL("http://www.118114ok.com/resin-admin/"); // URL
- in = url.openStream(); // URL
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- String inputLine = "";
- String pageStr="";
- while ((inputLine = reader.readLine()) != null)
- {
-
- pageStr+=inputLine;
- }
- String regex = "\\d*\\.\\d*\\.\\d*\\.\\d*";
- Pattern p = Pattern.compile(regex);
- Matcher m = p.matcher(pageStr);
- String val = null;
- if (m.find()){
- val = m.group();
- }
- return val;
- }catch (Exception e) {
- System.err.println(e);
- System.err.println("Usage: java GetURL []");
- } finally { // ζҪر
- try {
- in.close();
- out.close();
- } catch (Exception e) {
- }
- }
- return null;
- }
- public static void main(String[] args){
- String result = getUrl();
- System.err.println(result);
- }
-}
\ No newline at end of file
diff --git a/yin-control/src/main/java/jetty/JettyServer.java b/yin-control/src/main/java/jetty/JettyServer.java
index 8731eef..f519b54 100644
--- a/yin-control/src/main/java/jetty/JettyServer.java
+++ b/yin-control/src/main/java/jetty/JettyServer.java
@@ -1,73 +1,73 @@
-package jetty;
-
-import javax.naming.ConfigurationException;
-
-import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.eclipse.jetty.util.log.StdErrLog;
-import org.eclipse.jetty.webapp.WebAppContext;
-
-import com.yin.common.util.ConfigUtil;
-
-/**
- * @author hongxia.huhx GuahaoJettyServer for Jetty
- */
-public class JettyServer {
-
- /** port */
- private static int port = 11056;
-
- public static int getPort() {
- return port;
- }
-
- protected String charset = "UTF-8";
-
- public JettyServer() {
- }
-
- /**
- *
- *
- * @throws ConfigurationException
- */
- public void start() {
- try{
- port=Integer.parseInt(ConfigUtil.get("port"));
- }catch(Exception ex){}
- // Jetty־
- System.setProperty("org.eclipse.jetty.util.log.class", StdErrLog.class.getName());
-
- Server server = new Server();
-
- //
- Connector connector = new SelectChannelConnector();
- connector.setPort(port);
- connector.setRequestHeaderSize(16246);
- server.setConnectors(new Connector[] { connector });
-
- // context
- WebAppContext context = new WebAppContext();
- context.setResourceBase("./WebRoot");
- context.setContextPath("/");
- // PS:ǶʽJettyӦõǰ̵ClassPathýʹWebAppClassLoderWEB-INF/libĿ¼jar
- context.setClassLoader(Thread.currentThread().getContextClassLoader());
- context.setParentLoaderPriority(true);
- server.setHandler(context);
-
- // Server
- try {
- server.start();
- server.join();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public static void main(String[] args) {
- JettyServer userServer = new JettyServer();
-
- userServer.start();
- }
+package jetty;
+
+import javax.naming.ConfigurationException;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.util.log.StdErrLog;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+import com.yin.common.util.ConfigUtil;
+
+/**
+ * @author hongxia.huhx GuahaoJettyServer for Jetty
+ */
+public class JettyServer {
+
+ /** port */
+ private static int port = 11056;
+
+ public static int getPort() {
+ return port;
+ }
+
+ protected String charset = "UTF-8";
+
+ public JettyServer() {
+ }
+
+ /**
+ * 服务器启动。
+ *
+ * @throws ConfigurationException
+ */
+ public void start() {
+ try{
+ port=Integer.parseInt(ConfigUtil.get("port"));
+ }catch(Exception ex){}
+ // 设置Jetty日志
+ System.setProperty("org.eclipse.jetty.util.log.class", StdErrLog.class.getName());
+
+ Server server = new Server();
+
+ // 设置连接器
+ Connector connector = new SelectChannelConnector();
+ connector.setPort(port);
+ connector.setRequestHeaderSize(16246);
+ server.setConnectors(new Connector[] { connector });
+
+ // 设置context
+ WebAppContext context = new WebAppContext();
+ context.setResourceBase("./WebRoot");
+ context.setContextPath("/");
+ // PS:嵌入式的Jetty,应用当前工程的ClassPath,如果不设置将使用WebAppClassLoder,WEB-INF/lib目录加载jar。
+ context.setClassLoader(Thread.currentThread().getContextClassLoader());
+ context.setParentLoaderPriority(true);
+ server.setHandler(context);
+
+ // 启动Server
+ try {
+ server.start();
+ server.join();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void main(String[] args) {
+ JettyServer userServer = new JettyServer();
+
+ userServer.start();
+ }
}
\ No newline at end of file
diff --git a/yin-control/src/resources/config.properties b/yin-control/src/main/resources/config.properties
similarity index 100%
rename from yin-control/src/resources/config.properties
rename to yin-control/src/main/resources/config.properties