FileDocCategorySizeDatePackage
MagnetConnection.javaAPI DocAzureus 3.0.3.43050Thu Jan 11 11:47:38 GMT 2007org.gudy.azureus2.core3.util.protocol.magnet

MagnetConnection

public class MagnetConnection extends HttpURLConnection
author
parg

Fields Summary
protected Socket
socket
protected static final String
NL
protected String
status
Constructors Summary
protected MagnetConnection(URL _url)

	
	
	
				 
	
		super( _url );
	
Methods Summary
public voidconnect()

		socket = new Socket( "127.0.0.1", MagnetURIHandler.getSingleton().getPort());
						
		String	get = "GET " + "/download/" + getURL().toString().substring( 7 ) + " HTTP/1.0\r\n";
		
		socket.getOutputStream().write( get.getBytes());
		
		socket.getOutputStream().flush();
	
public voiddisconnect()

		try{
			socket.close();
			
		}catch( Throwable e ){
			
			Debug.printStackTrace(e);
		}
	
public java.io.InputStreamgetInputStream()

		InputStream	is = socket.getInputStream();
		
		String	line = "";
		
		byte[]	buffer = new byte[1];

		byte[]	line_bytes		= new byte[2048];
		int		line_bytes_pos 	= 0;
		
		while(true){
		
			int	len = is.read( buffer );
			
			if ( len == -1 ){
				
				break;
			}
			
			line += (char)buffer[0];
			
			line_bytes[line_bytes_pos++] = buffer[0];
			
			if ( line.endsWith( NL )){
				
				line = line.trim();
				
				if ( line.length() == 0 ){
					
					break;
				}
				
				if ( line.startsWith( "X-Report:")){
					
					line = new String( line_bytes, 0, line_bytes_pos, "UTF-8" );
					
					line = line.substring( 9 );
										
					line = line.trim();
					
					status = Character.toUpperCase( line.charAt(0)) + line.substring(1);
				}
				
				line			= "";
				line_bytes_pos	= 0;
			}
		}
		
		return( is );
	
public intgetResponseCode()

		return( HTTP_OK );
	
public java.lang.StringgetResponseMessage()

		return( status );
	
public booleanusingProxy()

		return( false );