【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-TestRFC2616.java,希望本篇文章对您学习有所帮助。
// ========================================================================
// Copyright (c) 1999 Mort Bay Consulting (Australia) Pty. Ltd.
// $Id: TestRFC2616.java,v 3.33 2001/01/10 15:35:17 gregwilkins Exp $
// ========================================================================
package com.mortbay.HTTP;
import com.mortbay.HTTP.Handler.DumpHandler;
import com.mortbay.HTTP.Handler.NotFoundHandler;
import com.mortbay.HTTP.Handler.NullHandler;
import com.mortbay.HTTP.Handler.ResourceHandler;
import com.mortbay.HTTP.Handler.TestTEHandler;
import com.mortbay.Util.Code;
import com.mortbay.Util.IO;
import com.mortbay.Util.Resource;
import com.mortbay.Util.LineInput;
import com.mortbay.Util.Test;
import com.mortbay.Util.ThreadPool;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.G
ZIPOutputStream;
/* ------------------------------------------------------------ */
/** Test against RFC 2616.
*
* @version $Id: TestRFC2616.java,v 3.33 2001/01/10 15:35:17 gregwilkins Exp $
* @author Greg Wilkins (gregw)
*/
public class TestRFC2616
extends ThreadPool
implements HttpListener
{
private HttpServer _server;
private static File docRoot = null;
private static TestFileData [] testFiles = null;
/* -------------------------------------------------------------- */
//
// this inner class creates some files needed for testing of code
// involving the ResourceHandler. instead, it may be cleaner to
// subclass the handler or resource context to fetch data from
// this code instead of going to disk, but that would involve
// hacking up the production code to a much larger degree than
// is necessary to implement certain
desired features (Ranges)
//
// so, this class instead creates a "docroot/" directory with
// some small files in it. That way, you still dont have to
// worry about what your work dir is when you run the tests.
// drawback: it will overwrite these files if they exist. hopefully
// nobody will use the same bizarre file names.
//
// @author Helmut Hissen (hzh)
//
public final static String defaultTestRoot = "testdocs";
public final static String testFilePrefix = "alphabet";
public final static String testFileSuffix = ".txt";
class TestFileData {
File file;
String data;
String name;
String modDate;
Resource resource;
public TestFileData(File file, String data) throws IOException {
File docRoot = new File(file.getParent());
this.file = file;
this.data = data;
this.name = file.getName();
if ( !docRoot.exists() ) {
docRoot.mkdir();
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(data.getBytes());
fos.close();
Code.debug("created " + file.getPath());
try {
this.resource = Resource.newResource(
new URL("file", "localhost", file.getAbsolutePath())
);
this.modDate = HttpFields.__dateSend.format(new Date(resource.lastModified()));
}
catch (MalformedURLException mue) {
Code.warning(mue);
}
}
}
public final static String [] testFileChars = {
"abcdefghijklmnopqrstuvwxyz", // PLAIN TEXT ONLY PLEASE
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" // OTHERWISE: DEAL WITH TEXT ENCODING
};
public TestFileData[] initTestFileData(File docRoot) throws IOException {
TestFileData[] testFiles = new TestFileData[testFileChars.length];
for (int i = 0; i < testFileChars.length; i++) {
testFiles[i] = new TestFileData(
new File(docRoot, testFilePrefix + i + testFileSuffix),
testFileChars[