httpclienttimeout.java
来自「常用机器学习算法,java编写源代码,内含常用分类算法,包括说明文档」· Java 代码 · 共 76 行
JAVA
76 行
package edu.umass.cs.mallet.projects.dex.web;import sun.net.www.http.HttpClient;import sun.net.www.MessageHeader ;import sun.net.ProgressEntry ;import java.net.*;import java.io.*;public class HttpClientTimeout extends HttpClient{ public HttpClientTimeout(URL url, String proxy, int proxyPort) throws IOException { super(url, proxy, proxyPort); } public HttpClientTimeout(URL url) throws IOException { super(url, null, -1); } public void SetTimeout(int i) throws SocketException { this.timeout = i; serverSocket.setSoTimeout(i) ; } public boolean parseHTTP(MessageHeader header, ProgressEntry entry) throws java.io.IOException { if( this.timeout != -1 ) { try { serverSocket.setSoTimeout(timeout) ; } catch( SocketException e ) { throw new java.io.IOException("unable to set socket timeout!") ; } } return super.parseHTTP(header, entry) ; } /* This class has no public constructor for HTTP. This method is used to * get an HttpClient to the specifed URL. If there's currently an * active HttpClient to that server/port, you'll get that one. * * no longer syncrhonized -- it slows things down too much * synchronize at a higher level */ public static HttpClientTimeout GetNew(URL url) throws IOException { /* see if one's already around */ HttpClientTimeout ret = (HttpClientTimeout) kac.get(url); if (ret == null) { ret = new HttpClientTimeout (url); // CTOR called openServer() } else { ret.url = url; } // don't know if we're keeping alive until we parse the headers // for now, keepingAlive is false return ret; } public void Close() throws IOException { serverSocket.close(); } public Socket GetSocket() { return serverSocket; } int timeout;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?