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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? externalseedhttpdownloader.java

?? 這是我模仿window自帶的小游戲掃雷編的,很簡單,只實現(xiàn)了掃雷的基本功能,現(xiàn)拿出來與大家分享!
?? JAVA
字號:
/*
 * Created on 16-Dec-2005
 * Created by Paul Gardner
 * Copyright (C) 2005, 2006 Aelitis, All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 * AELITIS, SAS au capital de 46,603.30 euros
 * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
 *
 */

package com.aelitis.azureus.plugins.extseed.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
import java.util.StringTokenizer;

import org.gudy.azureus2.core3.util.Debug;

import com.aelitis.azureus.plugins.extseed.ExternalSeedException;

public class 
ExternalSeedHTTPDownloader 
{
	public static final String	NL = "\r\n";
	

	private URL			url;
	private String		user_agent;
	
	private int			last_response;
	private byte[]		last_response_data;
	
	public
	ExternalSeedHTTPDownloader(
		URL		_url,
		String	_user_agent )
	{
		url			= _url;
		user_agent	= _user_agent;
	}
	
	public void
	download(
		int									length,
		ExternalSeedHTTPDownloaderListener	listener,
		boolean								con_fail_is_perm_fail )
	
		throws ExternalSeedException
	{
		download( new String[0], new String[0], length, listener, con_fail_is_perm_fail );
	}
	
	public void
	downloadRange(
		long								offset,
		int									length,
		ExternalSeedHTTPDownloaderListener	listener,
		boolean								con_fail_is_perm_fail )
	
		throws ExternalSeedException
	{
		download( 	new String[]{ "Range" }, new String[]{ "bytes=" + offset + "-" + (offset+length-1)},
					length,
					listener,
					con_fail_is_perm_fail );
	}
	
	public void
	download(
		String[]							prop_names,
		String[]							prop_values,
		int									length,
		ExternalSeedHTTPDownloaderListener	listener,
		boolean								con_fail_is_perm_fail )
	
		throws ExternalSeedException
	{
		boolean	connected = false;
		
		InputStream	is	= null;
				
		String	outcome = "";
		
		try{
			// System.out.println( "Connecting to " + url + ": " + Thread.currentThread().getId());

			HttpURLConnection	connection = (HttpURLConnection)url.openConnection();
			
			connection.setRequestProperty( "Connection", "Keep-Alive" );
			connection.setRequestProperty( "User-Agent", user_agent );
			
			for (int i=0;i<prop_names.length;i++){
				
				connection.setRequestProperty( prop_names[i], prop_values[i] );
			}
			
			connection.connect();
			
			connected	= true;
			
			int	response = connection.getResponseCode();
			
			is = connection.getInputStream();

			last_response	= response;
			
			if ( 	response == HttpURLConnection.HTTP_ACCEPTED || 
					response == HttpURLConnection.HTTP_OK ||
					response == HttpURLConnection.HTTP_PARTIAL ){
								
				int	pos = 0;
				
				byte[]	buffer 		= null;
				int		buffer_pos	= 0;

				while( pos < length ){
					
					if ( buffer == null ){
						
						buffer = listener.getBuffer();
					}

					listener.setBufferPosition( buffer_pos );
					
					int	to_read = buffer.length-buffer_pos;
					
					int	permitted = listener.getPermittedBytes();
					
					if ( permitted < to_read ){
						
						to_read	= permitted;
					}
					
					int	len = is.read( buffer, buffer_pos, to_read );
					
					if ( len < 0 ){
						
						break;
					}
					
					listener.reportBytesRead( len );
					
					pos	+= len;
					
					buffer_pos	+= len;
					
					if ( buffer_pos == buffer.length ){
						
						listener.done();
						
						buffer		= null;
						buffer_pos	= 0;
					}
				}
				
				if ( pos != length ){
					
					String	log_str;
					
					if ( buffer == null ){
						
						log_str = "No buffer assigned";
						
					}else{
						
						log_str =  new String( buffer, 0, length );
						
						if ( log_str.length() > 64 ){
							
							log_str = log_str.substring( 0, 64 );
						}
					}
					
					outcome = "Connection failed: data too short - " + length + "/" + pos + " [" + log_str + "]";
					
					throw( new ExternalSeedException( outcome ));
				}
				
				outcome = "read " + pos + " bytes";
				
				// System.out.println( "download length: " + pos );
				
			}else{
				
				outcome = "Connection failed: " + connection.getResponseMessage();
				
				ExternalSeedException	error = new ExternalSeedException( outcome );
				
				error.setPermanentFailure( true );
				
				throw( error );
			}
		}catch( IOException e ){
			
			if ( con_fail_is_perm_fail && !connected ){
				
				outcome = "Connection failed: " + e.getMessage();
				
				ExternalSeedException	error = new ExternalSeedException( outcome );
				
				error.setPermanentFailure( true );
				
				throw( error );

			}else{
				
				outcome =  "Connection failed: " + Debug.getNestedExceptionMessage( e );
				
				ExternalSeedException excep = new ExternalSeedException( outcome, e );
				
				if ( e instanceof FileNotFoundException ){
					
					excep.setPermanentFailure( true );
				}
				
				throw( excep );
			}
		}catch( Throwable e ){
			
			if ( e instanceof ExternalSeedException ){
				
				throw((ExternalSeedException)e);
			}
			
			outcome = "Connection failed: " + Debug.getNestedExceptionMessage( e );
			
			throw( new ExternalSeedException("Connection failed", e ));
			
		}finally{
			
			// System.out.println( "Done to " + url + ": " + Thread.currentThread().getId() + ", outcome=" + outcome );

			if ( is != null ){
				
				try{
					is.close();
					
				}catch( Throwable e ){
					
				}
			}
		}
	}
	
	public void
	downloadSocket(
		int									length,
		ExternalSeedHTTPDownloaderListener	listener,
		boolean								con_fail_is_perm_fail )
	        	
	    throws ExternalSeedException
	{
		downloadSocket( new String[0], new String[0], length, listener, con_fail_is_perm_fail );
	}
	
	public void
	downloadSocket(
		String[]							prop_names,
		String[]							prop_values,
		int									length,
		ExternalSeedHTTPDownloaderListener	listener,
		boolean								con_fail_is_perm_fail )
	
		throws ExternalSeedException
	{
		Socket	socket	= null;
		
		boolean	connected = false;
		
		try{				
			String	output_header = 
				"GET " + url.getPath() + "?" + url.getQuery() + " HTTP/1.1" + NL +
				"Host: " + url.getHost() + (url.getPort()==-1?"":( ":" + url.getPort())) + NL +
				"Accept: */*" + NL +
				"Connection: Close" + NL +	// if we want to support keep-alive we'll need to implement a socket cache etc.
				"User-Agent: " + user_agent + NL;
		
			for (int i=0;i<prop_names.length;i++){
				
				output_header += prop_names[i] + ":" + prop_values[i] + NL;
			}
			
			output_header += NL;
			
			System.out.println( "header: " + output_header );
			
			socket = new Socket(  url.getHost(), url.getPort()==-1?url.getDefaultPort():url.getPort());
			
			connected	= true;
			
			OutputStream	os = socket.getOutputStream();
			
			os.write( output_header.getBytes( "ISO-8859-1" ));
			
			os.flush();
			
			InputStream is = socket.getInputStream();
			
			try{
				String	input_header = "";
				
				while( true ){
					
					byte[]	buffer = new byte[1];
					
					int	len = is.read( buffer );
					
					if ( len < 0 ){
						
						throw( new IOException( "input too short reading header" ));
					}
					
					input_header	+= (char)buffer[0];
					
					if ( input_header.endsWith(NL+NL)){
					
						break;
					}
				}
								
				// HTTP/1.1 403 Forbidden
				
				int	line_end = input_header.indexOf(NL);
				
				if ( line_end == -1 ){
					
					throw( new IOException( "header too short" ));
				}
				
				String	first_line = input_header.substring(0,line_end);
				
				StringTokenizer	tok = new StringTokenizer(first_line, " " );
				
				tok.nextToken();
				
				int	response = Integer.parseInt( tok.nextToken());
				
				last_response	= response;
	
				String	response_str	= tok.nextToken();				
				
				if ( 	response == HttpURLConnection.HTTP_ACCEPTED || 
						response == HttpURLConnection.HTTP_OK ||
						response == HttpURLConnection.HTTP_PARTIAL ){
					
					byte[]	buffer 		= null;
					int		buffer_pos	= 0;
					
					int	pos = 0;
					
					while( pos < length ){
						
						if ( buffer == null ){
							
							buffer = listener.getBuffer();
						}
						
						int	to_read = buffer.length-buffer_pos;
						
						int	permitted = listener.getPermittedBytes();
						
						if ( permitted < to_read ){
							
							to_read	= permitted;
						}
						
						int	len = is.read( buffer, buffer_pos, to_read );
						
						if ( len < 0 ){
							
							break;
						}
						
						listener.reportBytesRead( len );
						
						pos	+= len;
						
						buffer_pos	+= len;
						
						if ( buffer_pos == buffer.length ){
							
							listener.done();
							
							buffer		= null;
							buffer_pos	= 0;
						}
					}
					
					if ( pos != length ){
						
						String	log_str;
						
						if ( buffer == null ){
							
							log_str = "No buffer assigned";
							
						}else{
							
							log_str =  new String( buffer, 0, length );
							
							if ( log_str.length() > 64 ){
								
								log_str = log_str.substring( 0, 64 );
							}
						}
						
						throw( new ExternalSeedException("Connection failed: data too short - " + length + "/" + pos + " [" + log_str + "]" ));
					}
					
					// System.out.println( "download length: " + pos );
										
				}else if ( 	response == 503 ){
					
						// webseed support for temp unavail - read the data
					
					String	data_str = "";
					
					while( true ){
						
						byte[]	buffer = new byte[1];
						
						int	len = is.read( buffer );
						
						if ( len < 0 ){
							
							break;
						}
						
						data_str += (char)buffer[0];
					}
					
					last_response_data = data_str.getBytes();
				
				}else{
					
					ExternalSeedException	error = new ExternalSeedException("Connection failed: " + response_str );
					
					error.setPermanentFailure( true );
					
					throw( error );
				}
			}finally{
				
				is.close();
			}
			
		}catch( IOException e ){
			
			if ( con_fail_is_perm_fail && !connected ){
				
				ExternalSeedException	error = new ExternalSeedException("Connection failed: " + e.getMessage());
				
				error.setPermanentFailure( true );
				
				throw( error );

			}else{
				
				throw( new ExternalSeedException("Connection failed", e ));
			}
		}catch( Throwable e ){
			
			if ( e instanceof ExternalSeedException ){
				
				throw((ExternalSeedException)e);
			}
			
			throw( new ExternalSeedException("Connection failed", e ));
			
		}finally{
			
			if ( socket != null ){
				
				try{
					socket.close();
					
				}catch( Throwable e ){
				}
			}
		}
	}
	
	public int
	getLastResponse()
	{
		return( last_response );
	}
	
	public byte[]
	getLast503ResponseData()
	{
		return( last_response_data );
	}
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品视频在线视频| 91麻豆精品91久久久久同性| 亚洲成人www| 国产亚洲欧洲一区高清在线观看| 色素色在线综合| 国产成人午夜片在线观看高清观看| 一区二区三区日韩精品视频| 精品av久久707| 欧美日韩一区中文字幕| 波多野结衣欧美| 蜜桃久久久久久| 午夜av电影一区| 亚洲免费观看高清完整| 国产香蕉久久精品综合网| 777精品伊人久久久久大香线蕉| eeuss国产一区二区三区| 韩国一区二区三区| 青青草精品视频| 亚洲精品v日韩精品| 国产精品视频一二三区| 精品三级在线看| 91精品国产色综合久久ai换脸| 91首页免费视频| 成人avav在线| 国产高清精品网站| 久久91精品久久久久久秒播| 亚欧色一区w666天堂| 亚洲黄色在线视频| 国产精品美女一区二区| 国产三级一区二区三区| 精品福利二区三区| 日韩精品自拍偷拍| 日韩欧美国产一区二区在线播放| 欧美日本在线播放| 欧美日韩一区高清| 精品视频资源站| 欧美精品一级二级| 91精品国产综合久久国产大片| 欧美美女网站色| 欧美精品一卡两卡| 日韩一级免费观看| 精品少妇一区二区三区在线播放 | 欧美日韩免费电影| 在线一区二区视频| 欧美午夜电影在线播放| 欧美久久久久久久久| 欧美精品电影在线播放| 在线电影国产精品| 欧美一区二区高清| 精品国精品国产| 国产婷婷一区二区| 成人免费在线视频| 一区二区欧美国产| 香蕉加勒比综合久久| 日韩黄色片在线观看| 裸体健美xxxx欧美裸体表演| 久久爱另类一区二区小说| 国产综合色在线| 成人综合日日夜夜| 色老头久久综合| 欧美日韩精品一区二区在线播放| 欧美一级免费大片| 久久久午夜精品| 国产精品成人午夜| 亚洲国产成人porn| 国内欧美视频一区二区| 不卡av在线网| 欧美三区在线观看| 26uuu亚洲综合色欧美| 日本一区二区不卡视频| 亚洲激情中文1区| 日本女人一区二区三区| 国产一本一道久久香蕉| 91蜜桃在线观看| 日韩视频123| 国产精品电影一区二区| 亚洲国产一区二区三区青草影视| 免费人成在线不卡| 成人av资源在线观看| 欧美日韩中文字幕精品| 久久一夜天堂av一区二区三区 | 日韩理论片网站| 日韩主播视频在线| 国产乱码精品一品二品| 91丨九色丨蝌蚪富婆spa| 日韩欧美中文字幕精品| 18欧美亚洲精品| 免费观看30秒视频久久| 99久久婷婷国产| 日韩欧美国产一区在线观看| 亚洲男人的天堂网| 男人的j进女人的j一区| 色一情一乱一乱一91av| 久久色.com| 香蕉成人伊视频在线观看| 国产不卡一区视频| 91精品午夜视频| 亚洲色图欧美激情| 精品一区二区三区欧美| 欧美亚洲自拍偷拍| 国产欧美日韩中文久久| 热久久一区二区| 色女孩综合影院| 日本一区二区三级电影在线观看| 丝瓜av网站精品一区二区| av不卡一区二区三区| 精品美女在线播放| 日韩经典中文字幕一区| 日本韩国一区二区| 国产精品麻豆99久久久久久| 久久99精品国产麻豆婷婷洗澡| 欧美午夜精品免费| 最新成人av在线| 成人午夜电影网站| 久久综合九色综合久久久精品综合 | 亚洲欧美视频一区| 国产福利91精品| 欧美成人vr18sexvr| 婷婷综合在线观看| 色妞www精品视频| 成人欧美一区二区三区黑人麻豆| 国产一区二区免费视频| 欧美电视剧免费全集观看| 午夜精品久久久久久久久久久 | 久久99精品久久久久婷婷| 欧美午夜电影在线播放| 中文字幕在线免费不卡| 色狠狠av一区二区三区| 欧美三级资源在线| 综合久久给合久久狠狠狠97色| 精品成人一区二区三区| 香蕉加勒比综合久久| 粉嫩嫩av羞羞动漫久久久| 精品国产免费一区二区三区四区 | 日本欧美在线观看| 精品视频免费看| 一区二区三区电影在线播| av激情综合网| 专区另类欧美日韩| 本田岬高潮一区二区三区| 欧美高清在线视频| jlzzjlzz欧美大全| 中文字幕一区二区三区蜜月| 91精品国产色综合久久ai换脸 | 亚洲图片欧美视频| 中文字幕一区二区5566日韩| 成人免费视频app| 国产精品免费免费| 91丝袜呻吟高潮美腿白嫩在线观看| 国产精品家庭影院| 色综合婷婷久久| 亚洲国产综合在线| 日韩精品一区二区三区在线播放| 久久国产免费看| 中文在线一区二区| 91亚洲国产成人精品一区二区三 | 国产精品美女一区二区三区| av欧美精品.com| 亚洲最新视频在线播放| 欧美日韩国产乱码电影| 蜜桃视频在线一区| 中文字幕欧美国产| 在线中文字幕一区| 久久99国产精品免费网站| 国产精品久久久久婷婷二区次| 色屁屁一区二区| 男男视频亚洲欧美| 国产精品午夜电影| 欧美日韩一区视频| 国产曰批免费观看久久久| 国产精品不卡一区| 欧美乱妇20p| 国产精品资源在线观看| 一区二区激情小说| 精品国产麻豆免费人成网站| 盗摄精品av一区二区三区| 亚洲一区二区三区视频在线 | 国产成人自拍在线| 一区二区视频在线看| 日韩一区二区三区免费看| 国产精品亚洲专一区二区三区| 亚洲精品网站在线观看| 欧美成人激情免费网| 91精品福利在线| 国产一区二区三区久久悠悠色av| 亚洲精品中文字幕在线观看| 精品久久久久一区| 91久久一区二区| 国产成人亚洲精品狼色在线| 亚洲成人一区在线| 国产精品美女一区二区| 91精品中文字幕一区二区三区| 顶级嫩模精品视频在线看| 日韩精品亚洲专区| 亚洲欧美偷拍三级| 日本一区二区成人| 精品美女在线播放| 欧美日韩卡一卡二| 色激情天天射综合网| 国产成人鲁色资源国产91色综 |