private static boolean arrEquals(byte[] a1, byte[] a2) { if (a1 == a2) return true; if (a1 == null || a2 == null) return false; int length = a1.length; if (a2.length != length) return false; int j = 0, k = 1; while (j < length) { if (a1[j] != a2[j]) return false; j += 2; } while (k < length) { if (a1[k] != a2[k]) return false; k += 2; } return true; }
/**
* 忽略大小写比较
*
* @param src
* @param cmd
* @return
*/
private boolean ignoreEquals(byte[] src, String cmd) {
int len2 = cmd.length();
int len1 = src.length;
if (len2 != len1)
return false;
int res = 0;
int len = len1 > len2 ? len2 : len1;
while ((res = src[--len] - cmd.charAt(len)) == 0 || res == 32
|| res == -32) {
return true;
}
return false;
}
package com.czp.utils; import java.io.File; import java.util.EnumSet; import java.util.EventListener; import java.util.Properties; import javax.servlet.DispatcherType; import javax.servlet.Filter; import javax.servlet.MultipartConfigElement; import javax.servlet.http.HttpServlet; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.webapp.WebAppContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * Function:web容器类,负责启动web服务<br> * 文件上传流程:<br> * 1.保存到图片数据到FastDFS<br> * 2.将FastDFS返回的ID存储到ES<br> * * Date :2015年12月11日 <br> * Author :coder_czp@126.com<br> * Copyright (c) 2015,coder_czp@126.com All Rights Reserved. */ public class WebContainer { private int port; private Server server; private String warPath; private int maxUploadSize; private String configPath; private WebAppContext context; public static final int fileSizeThreshold = 262144; public static final String CFG_FILE = "config_file"; private static Logger logger = LoggerFactory.getLogger(WebContainer.class); private static String key = "org.eclipse.jetty.servlet.Default.useFileMappedBuffer"; public WebContainer(String configPath) { parseConfig(configPath); this.configPath = configPath; this.server = new Server(port); this.context = new WebAppContext(); addWebGlobObject(context); context.setInitParameter(key, "false"); context.setParentLoaderPriority(true); context.setResourceBase(warPath); server = new Server(port); server.setHandler(context); } /** * 添加监听器 * * @param listener */ public void addEventListener(EventListener listener) { context.addEventListener(listener); } /** * 添加filter * * @param filter */ public void addFilter(Class<? extends Filter> cls, String mapping) { EnumSet<DispatcherType> type = EnumSet.of(DispatcherType.REQUEST); context.addFilter(cls, mapping, type); } /** * 添加servlet * * @param cls * @param mapping */ public void addServlet(Class<? extends HttpServlet> cls, String mapping) { context.addServlet(cls, mapping); } /** * 添加servlet * * @param cls * @param mapping */ public void addUploadServlet(Class<? extends HttpServlet> cls, String mapping) { File uploadTmpPath = new File("./webTemp"); if (!uploadTmpPath.exists()) uploadTmpPath.mkdir(); String path = uploadTmpPath.getAbsolutePath(); MultipartConfigElement cfg = new MultipartConfigElement(path, maxUploadSize, maxUploadSize, fileSizeThreshold); ServletHolder upload = new ServletHolder(cls); upload.getRegistration().setMultipartConfig(cfg); context.addServlet(upload, mapping); } public void start() throws Exception { logger.info("server running at:{}", port); server.start(); } /** * 停止web服务 * * @throws Exception */ public void stop() throws Exception { server.stop(); } /** * 添加web应用的全局参数,这些参数在整个web运行期 只存在一个实例 * * @param context */ private void addWebGlobObject(WebAppContext context) { context.setAttribute(CFG_FILE, configPath); } private void parseConfig(String configPath) { try { Properties cfg = PubTools.loadCfgFromFile(configPath); warPath = cfg.getProperty("web_dir"); port = Integer.valueOf(cfg.getProperty("web_port")); maxUploadSize = Integer.valueOf(cfg.getProperty("max_upload_size")); } catch (Exception e) { throw new RuntimeException(e); } } }
http://boendev.iteye.com/blog/882479
http://blog.csdn.net/jiubugeinifo/article/details/42024915
http://linuxtools-rst.readthedocs.org/zh_CN/latest/tool/iostat.html
http://blog.csdn.net/hdutigerkin/article/details/7517390 【epoll】
http://blog.csdn.net/ithomer/article/details/8000466