???????Java??????
???????????? ???????[ 2014/6/19 10:54:52 ] ????????Java ???????
/**
*
*/
package iotest.serversocket;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* @author Brandon B. Lin
*
*/
public class SingleFileHttpServer extends Thread {
private byte[] content;
private byte[] header;
private int port = 80;
public SingleFileHttpServer(String data?? String encoding?? String MIMEType??
int port) throws UnsupportedEncodingException {
this(data.getBytes(encoding)?? encoding?? MIMEType?? port);
}
public SingleFileHttpServer(byte[] data?? String encoding?? String MIMEType??
int port) throws UnsupportedEncodingException {
this.content = data;
this.port = port;
createHeader(encoding?? MIMEType);
}
private void createHeader(String encoding?? String MIMEType)
throws UnsupportedEncodingException {
String header = "HTTP/1.0 200 OK
" + "Server: OneFIle 1.0
"
+ "Content-length: " + content.length + "
"
+ "Content-type: " + MIMEType + "
";
this.header = header.getBytes(encoding);
}
@Override
public void run() {
try {
ServerSocket server = new ServerSocket(port);
log(server.getLocalPort());
while (true) {
respond(server);
}
} catch (IOException exception) {
System.err.println("Could not start server. Port Occupied!");
}
}
private void log(int port) {
System.out.println("Accepting connection on port " + port);
System.out.println("Data to be sent: ");
try {
System.out.write(content);
} catch (IOException e) {
e.printStackTrace();
}
}
private void respond(ServerSocket server) {
Socket connection = null;
try {
connection = server.accept();
String request = readRequestFromSocket(connection);
boolean writeHeader = (request.toString().indexOf("HTTP/") != -1);
writeToSocket(connection?? writeHeader);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null)
try {
connection.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????