亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fileservlet.java

?? 用java開發的
?? JAVA
字號:
// FileServlet - servlet similar to a standard httpd
//
// Copyright (C)1996,1998 by Jef Poskanzer <jef@acme.com>. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// Visit the ACME Labs Java page for up-to-date versions of this and other
// fine Java utilities: http://www.acme.com/java/
// 
// All enhancements Copyright (C)1998-2005 by Dmitriy Rogatkin
// http://tjws.sourceforge.net

package Acme.Serve;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Acme.Utils;

/// Servlet similar to a standard httpd.
// <P>
// Implements the "GET" and "HEAD" methods for files and directories.
// Handles index.html, index.htm, default.htm, default.html.
// Redirects directory URLs that lack a trailing /.
// Handles If-Modified-Since.
// <P>
// <A HREF="/resources/classes/Acme/Serve/FileServlet.java">Fetch the software.</A><BR>
// <A HREF="/resources/classes/Acme.tar.Z">Fetch the entire Acme package.</A>
// <P>
// @see Acme.Serve.Serve

public class FileServlet extends HttpServlet {

	// We keep a single throttle table for all instances of the servlet.
	// Normally there is only one instance; the exception is subclasses.
	static Acme.WildcardDictionary throttleTab = null;

	static final String[] DEFAULTINDEXPAGES = { "index.html", "index.htm", "default.htm", "default.html" };

	static final DecimalFormat lengthftm = new DecimalFormat("#");

	static final String BYTES_UNIT = "bytes";

	protected String charSet = Serve.UTF8;// "iso-8859-1";

	private static final boolean logenabled = false;

	// true;

	private Method canExecute, getFreeSpace;

	// / Constructor.
	public FileServlet() {
		try {
			canExecute = File.class.getMethod("canExecute", Utils.EMPTY_CLASSES);
		} catch (SecurityException e) {
		} catch (NoSuchMethodException e) {
		}
		try {
			getFreeSpace = File.class.getMethod("getFreeSpace", Utils.EMPTY_CLASSES);
		} catch (SecurityException e) {
		} catch (NoSuchMethodException e) {
		}
	}

	// / Constructor with throttling.
	// @param throttles filename containing throttle settings
	// @param charset used for displaying directory page
	// @see ThrottledOutputStream
	public FileServlet(String throttles, String charset) throws IOException {
		this();
		if (charset != null)
			this.charSet = charset;
		readThrottles(throttles);
	}

	private void readThrottles(String throttles) throws IOException {
		Acme.WildcardDictionary newThrottleTab = ThrottledOutputStream.parseThrottleFile(throttles);
		if (throttleTab == null)
			throttleTab = newThrottleTab;
		else {
			// Merge the new one into the old one.
			Enumeration keys = newThrottleTab.keys();
			Enumeration elements = newThrottleTab.elements();
			while (keys.hasMoreElements()) {
				Object key = keys.nextElement();
				Object element = elements.nextElement();
				throttleTab.put(key, element);
			}
		}
	}

	// / Returns a string containing information about the author, version, and
	// copyright of the servlet.
	public String getServletInfo() {
		return "servlet similar to a standard httpd";
	}

	// / Services a single request from the client.
	// @param req the servlet request
	// @param req the servlet response
	// @exception ServletException when an exception has occurred
	public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		boolean headOnly;
		if (req.getMethod().equalsIgnoreCase("get"))
			headOnly = false;
		else if (req.getMethod().equalsIgnoreCase("head"))
			headOnly = true;
		else {
			res.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
			return;
		}
		req.setCharacterEncoding(Serve.UTF8);
		String path = Utils.canonicalizePath(req.getPathInfo());
		//res.setBufferSize(Utils.COPY_BUF_SIZE/2);
		dispatchPathname(req, res, headOnly, path);
	}

	private void dispatchPathname(HttpServletRequest req, HttpServletResponse res, boolean headOnly, String path)
			throws IOException {
		String filename = req.getPathTranslated() != null ? req.getPathTranslated().replace('/', File.separatorChar)
				: "";
		File file = new File(filename);
		log("showing '" + filename + "' for path " + path);
		if (file.exists()) {
			if (!file.isDirectory())
				serveFile(req, res, headOnly, path, file);
			else {
				log("showing dir " + file);
				if (redirectDirectory(req, res, path, file) == false)
					showIdexFile(req, res, headOnly, path, filename);
			}
		} else
			res.sendError(HttpServletResponse.SC_NOT_FOUND);
	}

	private void showIdexFile(HttpServletRequest req, HttpServletResponse res, boolean headOnly, String path,
			String parent) throws IOException {
		log("showing index in directory " + parent);
		for (int i = 0; i < DEFAULTINDEXPAGES.length; i++) {
			File indexFile = new File(parent, DEFAULTINDEXPAGES[i]);
			if (indexFile.exists()) {
				serveFile(req, res, headOnly, path, indexFile);
				return;
			}
		}
		// index not found
		serveDirectory(req, res, headOnly, path, new File(parent));
	}

	private void serveFile(HttpServletRequest req, HttpServletResponse res, boolean headOnly, String path, File file)
			throws IOException {
		log("getting " + file);
		if (logenabled) {
			Enumeration enh = req.getHeaderNames();
			while(enh.hasMoreElements()) {
				String hn = (String )enh.nextElement();
				log("hdr:"+hn+":"+req.getHeader(hn));
			}
		}
		if (!file.canRead()) {
			res.sendError(HttpServletResponse.SC_FORBIDDEN);
			return;
		} else
			// by Niel Markwick
			try {
				file.getCanonicalPath();
			} catch (Exception e) {
				res.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden, exception:" + e);
				return;
			}

		// Handle If-Modified-Since.
		res.setStatus(HttpServletResponse.SC_OK);
		long lastMod = file.lastModified();
		String ifModSinceStr = req.getHeader("If-Modified-Since");
		long ifModSince = -1;
		if (ifModSinceStr != null) {
			int semi = ifModSinceStr.indexOf(';');
			if (semi != -1)
				ifModSinceStr = ifModSinceStr.substring(0, semi);
			try {
				ifModSince = DateFormat.getDateInstance().parse(ifModSinceStr).getTime();
			} catch (Exception ignore) {
				log("Can't parse " + ifModSinceStr + " " + ignore);
			}
		}
		if (ifModSince != -1 && ifModSince >= lastMod) {
			res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
			headOnly = true;
		}
		// TODO add processing If-None-Match, If-Unmodified-Since and If-Match
		res.setContentType(getServletContext().getMimeType(file.getName()));
		long flen = file.length();
		// check for range
		String range = req.getHeader("Range");
		long sr = 0;
		long er = -1;
		if (range != null) {
			log("Range:"+range);
			if (range.regionMatches(true, 0, BYTES_UNIT, 0, BYTES_UNIT.length())) {
				int i = range.indexOf('-');
				if (i > 0) {
					try {
						sr = Long.parseLong(range.substring(BYTES_UNIT.length() + 1, i));
						if (sr < 0)
							throw new NumberFormatException("Invalid start range value:"+sr);
						try {
							er = Long.parseLong(range.substring(i + 1));
						}catch(NumberFormatException nfe) {
							er = flen-1;
						}
					}catch(NumberFormatException nfe) {
						
					}
				} // else invalid range? ignore?
			} // else other units not supported
			log("range values "+sr+ " to "+er);
		}
		long clen = er < 0 ? flen : (er - sr + 1);
		if (clen < Integer.MAX_VALUE)
			res.setContentLength((int) clen);
		else
			res.setHeader("Content-Length", Long.toString(clen));
		res.setDateHeader("Last-modified", lastMod);

		if (er > 0) {
			if (sr > er || er >= flen) {
				// TODO If-Range presence can change behavior
				res.setHeader("Content-Range", BYTES_UNIT + " */" + flen);
				res.setStatus(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
				return;
			}
			res.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
			res.setHeader("Content-Range", BYTES_UNIT + " " + sr + '-' + er + '/' + flen);
			log("content-range:"+BYTES_UNIT + " " + sr + '-' + er + '/' + flen);
		}
		// String ifRange = req.getHeader("If-Range");
		// res.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);

		OutputStream out = null;
		InputStream in = null;
		try {
			out = res.getOutputStream();
			if (!headOnly) {
				// Check throttle.
				if (throttleTab != null) {
					ThrottleItem throttleItem = (ThrottleItem) throttleTab.get(path);
					if (throttleItem != null) {
						// !!! Need to count for multiple simultaneous fetches.
						out = new ThrottledOutputStream(out, throttleItem.getMaxBps());
					}
				}

				in = new FileInputStream(file);
				while (sr > 0) {
					long sl = in.skip(sr);
					if (sl > 0)
						sr -= sl;
					else {
						res.sendError(HttpServletResponse.SC_CONFLICT, "Conflict");
						// better can be Internal Server Error
						return;
					}
				}
				copyStream(in, out, clen);
			}
		} finally {
			if (in != null)
				try {
					in.close();
				} catch (IOException ioe) {
				}
			if (out != null) {
				out.flush();
				out.close();
			}
		}
	}

	// / Copy a file from in to out.
	// Sub-classes can override this in order to do filtering of some sort.
	public void copyStream(InputStream in, OutputStream out, long len) throws IOException {
		Acme.Utils.copyStream(in, out, len);
	}

	private void serveDirectory(HttpServletRequest req, HttpServletResponse res, boolean headOnly, String path,
			File file) throws IOException {
		log("indexing " + file);
		if (!file.canRead()) {
			res.sendError(HttpServletResponse.SC_FORBIDDEN);
			return;
		}
		res.setStatus(HttpServletResponse.SC_OK);
		res.setContentType("text/html;charset=" + charSet);
		OutputStream out = res.getOutputStream();
		if (!headOnly) {
			PrintStream p = new PrintStream(new BufferedOutputStream(out), false, charSet); // 1.4
			p.println("<HTML><HEAD>");
			p.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=" + charSet + "\">");
			p.println("<TITLE>Index of " + path + "</TITLE>");
			p.println("</HEAD><BODY " + Serve.BGCOLOR);
			p.println("><H2>Index of " + path + "</H2>");
			p.println("<PRE>");
			p.println("mode         bytes  last-changed    name");
			p.println("<HR>");
			String[] names = file.list();
			// TODO consider not case sensetive search
			Arrays.sort(names);
			long total = 0;
			for (int i = 0; i < names.length; ++i) {
				File aFile = new File(file, names[i]);
				String aFileType;
				long aFileLen;
				if (aFile.isDirectory())
					aFileType = "d";
				else if (aFile.isFile())
					aFileType = "-";
				else
					aFileType = "?";
				String aFileRead = (aFile.canRead() ? "r" : "-");
				String aFileWrite = (aFile.canWrite() ? "w" : "-");
				String aFileExe = "-";
				if (canExecute != null)
					try {
						if (((Boolean) canExecute.invoke(aFile, Utils.EMPTY_OBJECTS)).booleanValue())
							aFileExe = "x";
					} catch (IllegalArgumentException e) {
					} catch (IllegalAccessException e) {
					} catch (InvocationTargetException e) {
					}
				String aFileSize = lengthftm.format(aFileLen = aFile.length());
				total += (aFileLen + 1023) / 1024; // 
				while (aFileSize.length() < 12)
					aFileSize = " " + aFileSize;
				String aFileDate = Acme.Utils.lsDateStr(new Date(aFile.lastModified()));
				while (aFileDate.length() < 14)
					aFileDate += " ";
				String aFileDirsuf = (aFile.isDirectory() ? "/" : "");
				String aFileSuf = (aFile.isDirectory() ? "/" : "");
				p.println(aFileType + aFileRead + aFileWrite + aFileExe + "  " + aFileSize + "  " + aFileDate + "  "
						+ "<A HREF=\"" + URLEncoder.encode(names[i], charSet) /* 1.4 */
						+ aFileDirsuf + "\">" + names[i] + aFileSuf + "</A>");
			}
			if (total != 0)
				total += 3;
			p.println("total " + total);
			p.println("</PRE>");
			p.println("<HR>");
			Serve.Identification.writeAddress(p);
			p.println("</BODY></HTML>");
			p.flush();
		}
		out.close();
	}

	/**
	 * 
	 * @param req
	 *            http request
	 * @param res
	 *            http response
	 * @param path
	 *            web path
	 * @param file
	 *            file system path
	 * @return true if redirection required and happened
	 * @throws IOException
	 *             in redirection
	 */
	private boolean redirectDirectory(HttpServletRequest req, HttpServletResponse res, String path, File file)
			throws IOException {
		int pl = path.length();
		if (pl > 0 && path.charAt(pl - 1) != '/') {
			// relative redirect
			int sp = path.lastIndexOf('/');
			if (sp < 0)
				path += '/';
			else
				path = path.substring(sp + 1) + '/';
			log("redirecting dir " + path);
			res.sendRedirect(path);
			return true;
		}
		return false;
	}

	public void log(String msg) {
		if (logenabled)
			super.log(msg);
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
奇米888四色在线精品| 欧美色精品在线视频| 亚洲成a天堂v人片| 亚洲情趣在线观看| 亚洲美女偷拍久久| 亚洲品质自拍视频| 亚洲妇熟xx妇色黄| 亚洲成a人v欧美综合天堂下载| 一区二区三区在线免费视频| 国产精品国产精品国产专区不片| 国产伦精品一区二区三区在线观看 | 国产精品全国免费观看高清| 欧美高清激情brazzers| 欧美艳星brazzers| 欧美日韩国产精品自在自线| 欧美精选一区二区| 欧美一区二区三区性视频| 91精品欧美综合在线观看最新| 精品一区二区久久久| 免费美女久久99| 国产一区二三区| 国产成人亚洲精品狼色在线 | 91色婷婷久久久久合中文| av在线播放不卡| 欧美日韩一级大片网址| 欧美高清激情brazzers| 日韩免费视频线观看| xvideos.蜜桃一区二区| 中国色在线观看另类| 亚洲综合男人的天堂| 视频一区视频二区中文| 久久成人18免费观看| www.视频一区| 在线播放中文一区| 国产三级欧美三级日产三级99 | 欧美一区二区三区喷汁尤物| 欧美电视剧在线观看完整版| 亚洲国产成人私人影院tom| 亚洲精品亚洲人成人网| 免费高清在线一区| 成人黄页在线观看| 日韩欧美一二区| 欧美激情一区二区三区在线| 一区二区三区欧美在线观看| 久久精品国产久精国产| 欧美xxx久久| 怡红院av一区二区三区| 黑人巨大精品欧美一区| 日本韩国一区二区| 26uuu亚洲综合色欧美| 一区二区三区欧美| 国产精品77777| 91 com成人网| 亚洲精品午夜久久久| 国产乱码精品一区二区三区忘忧草| 亚洲成人自拍偷拍| 国产精品综合一区二区三区| 欧美视频一区二区三区四区| 国产精品理论在线观看| 日韩电影在线观看网站| 色94色欧美sute亚洲线路二| 国产日产欧美精品一区二区三区| 久久久国产综合精品女国产盗摄| 欧美一区二区三区免费观看视频 | 成人av片在线观看| 欧美va在线播放| 五月天中文字幕一区二区| 成人av在线看| 国产欧美日韩三区| 韩国欧美一区二区| 日韩欧美在线一区二区三区| 午夜国产精品一区| 欧美日韩日日摸| 一区二区三区免费观看| 色综合一区二区三区| 国产精品网曝门| 国产精品影视在线观看| 精品国内二区三区| 久久丁香综合五月国产三级网站| 国产精品一二一区| 久久久久国产精品麻豆| 免费人成网站在线观看欧美高清| 亚洲日本青草视频在线怡红院| 18欧美乱大交hd1984| jizz一区二区| 欧美激情一区二区三区不卡 | 国产99久久久久| 精品国产乱码久久久久久图片| 国产日韩欧美综合在线| 狠狠色综合色综合网络| 久久精品视频一区二区| 99久久精品一区二区| 亚洲色图欧洲色图| 欧美午夜在线一二页| 亚洲777理论| 日韩精品中文字幕在线不卡尤物| 中文字幕欧美日韩一区| 成人三级伦理片| 成人免费小视频| 在线免费观看一区| 亚洲成av人影院| 337p日本欧洲亚洲大胆精品 | 中文字幕亚洲在| 国模冰冰炮一区二区| 国产欧美日韩精品一区| 成人黄色在线网站| 亚洲高清免费观看高清完整版在线观看| 久久精品国产精品亚洲精品| www国产成人免费观看视频 深夜成人网| 国产精品嫩草久久久久| 91久久久免费一区二区| 日韩激情一区二区| 国产亚洲欧美在线| av一二三不卡影片| 天天综合色天天综合| 亚洲国产成人私人影院tom| 欧美午夜不卡在线观看免费| 久久精品免费看| 亚洲欧美经典视频| 精品日产卡一卡二卡麻豆| 91农村精品一区二区在线| 日本亚洲最大的色成网站www| 在线看一区二区| 国产精品一区二区视频| 亚洲高清久久久| 中文字幕精品在线不卡| 欧美久久一区二区| 色综合久久综合| 国产一区三区三区| 欧美韩国日本综合| 不卡av免费在线观看| 亚洲第一在线综合网站| 欧美大片一区二区三区| 久久亚洲影视婷婷| 3d动漫精品啪啪1区2区免费| 色综合视频在线观看| 国产精品一级片| 久久精品国产99| 午夜精品久久久久久久| 亚洲欧美怡红院| 国产精品久久久久精k8| 国产视频一区二区在线| 日韩欧美成人午夜| 91精品婷婷国产综合久久| 欧洲av一区二区嗯嗯嗯啊| 成av人片一区二区| 丰满少妇在线播放bd日韩电影| 久久婷婷色综合| 欧美一区二区三区不卡| 欧美乱妇15p| 91论坛在线播放| 99精品久久久久久| 成人毛片视频在线观看| 午夜视频一区在线观看| 一区二区三区蜜桃| 亚洲老司机在线| 国产精品免费视频网站| 欧美一区二区三区系列电影| 欧美成人精品福利| 国产毛片精品视频| 麻豆成人免费电影| 裸体健美xxxx欧美裸体表演| 丝瓜av网站精品一区二区| 亚洲成a人v欧美综合天堂下载 | 99久久综合狠狠综合久久| 国产精品资源网| jiyouzz国产精品久久| 99免费精品视频| 色国产综合视频| 欧美日韩专区在线| 日韩一区二区在线看片| 欧美一级爆毛片| 欧美精品一区二区三区一线天视频| 成人网页在线观看| 色综合色狠狠综合色| 午夜不卡av免费| 成人激情综合网站| 日本久久一区二区| 91麻豆精品国产综合久久久久久 | 国产精品久久久久7777按摩| 亚洲欧美一区二区在线观看| 亚洲狠狠爱一区二区三区| 亚洲国产欧美在线| 国产麻豆精品theporn| av一区二区三区四区| 欧美人与z0zoxxxx视频| 久久亚洲精精品中文字幕早川悠里 | 亚洲乱码中文字幕综合| 91豆麻精品91久久久久久| 911精品国产一区二区在线| 欧美一级日韩不卡播放免费| 久久久天堂av| 亚洲亚洲精品在线观看| 久久99精品一区二区三区| 成人免费观看男女羞羞视频| 欧美日韩国产一区二区三区地区| aa级大片欧美| 欧美午夜免费电影| 亚洲国产高清aⅴ视频| 久久精品亚洲精品国产欧美|