📄 magnetconnection.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: MagnetConnection.java
package org.gudy.azureus2.core3.util.protocol.magnet;
import com.aelitis.net.magneturi.MagnetURIHandler;
import java.io.*;
import java.net.*;
import org.gudy.azureus2.core3.util.Debug;
public class MagnetConnection extends HttpURLConnection
{
protected Socket socket;
protected static final String NL = "\r\n";
protected String status;
protected MagnetConnection(URL _url)
{
super(_url);
status = "";
}
public void connect()
throws IOException
{
socket = new Socket("127.0.0.1", MagnetURIHandler.getSingleton().getPort());
String get = (new StringBuilder()).append("GET /download/").append(getURL().toString().substring(7)).append(" HTTP/1.0\r\n").toString();
socket.getOutputStream().write(get.getBytes());
socket.getOutputStream().flush();
}
public InputStream getInputStream()
throws IOException
{
InputStream is = socket.getInputStream();
String line = "";
byte buffer[] = new byte[1];
byte line_bytes[] = new byte[2048];
int line_bytes_pos = 0;
do
{
int len = is.read(buffer);
if (len == -1)
break;
line = (new StringBuilder()).append(line).append((char)buffer[0]).toString();
line_bytes[line_bytes_pos++] = buffer[0];
if (!line.endsWith("\r\n"))
continue;
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 = (new StringBuilder()).append(Character.toUpperCase(line.charAt(0))).append(line.substring(1)).toString();
}
line = "";
line_bytes_pos = 0;
} while (true);
return is;
}
public int getResponseCode()
{
return 200;
}
public String getResponseMessage()
{
return status;
}
public boolean usingProxy()
{
return false;
}
public void disconnect()
{
try
{
socket.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -