📄 resourcedownloaderurlimpl.java
字号:
super();
}
});
con = ssl_con;
} else
{
con = (HttpURLConnection)openConnection(url);
}
con.setRequestProperty("User-Agent", "Azureus 4.2.0.0");
con.setRequestProperty("Connection", "close");
if (use_compression)
con.addRequestProperty("Accept-Encoding", "gzip");
setRequestProperties(con, use_compression);
if (post_data != null)
{
con.setDoOutput(true);
con.setRequestMethod("POST");
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(post_data);
wr.flush();
}
con.connect();
response = con.getResponseCode();
if (response != 302 && response != 301)
break MISSING_BLOCK_LABEL_601;
move_to = con.getHeaderField("location");
if (move_to == null || !url.getProtocol().equalsIgnoreCase("http"))
break MISSING_BLOCK_LABEL_601;
URL move_to_url = new URL(URLDecoder.decode(move_to, "UTF-8"));
if (!move_to_url.getProtocol().equalsIgnoreCase("https"))
break MISSING_BLOCK_LABEL_601;
url = move_to_url;
follow_redirect = true;
if (temp_file != null)
temp_file.delete();
break MISSING_BLOCK_LABEL_1427;
Throwable e;
e;
boolean compressed;
if (response != 202 && response != 200)
{
setProperty("URL_HTTP_Response", new Long(response));
throw new ResourceDownloaderException((new StringBuilder()).append("Error on connect for '").append(trimForDisplay(url)).append("': ").append(Integer.toString(response)).append(" ").append(con.getResponseMessage()).toString());
}
getRequestProperties(con);
compressed = false;
this_mon.enter();
input_stream = con.getInputStream();
String encoding = con.getHeaderField("content-encoding");
if (encoding != null)
if (encoding.equalsIgnoreCase("gzip"))
{
compressed = true;
input_stream = new GZIPInputStream(input_stream);
} else
if (encoding.equalsIgnoreCase("deflate"))
{
compressed = true;
input_stream = new InflaterInputStream(input_stream);
}
this_mon.exit();
break MISSING_BLOCK_LABEL_810;
Exception exception;
exception;
this_mon.exit();
throw exception;
ByteArrayOutputStream baos;
FileOutputStream fos;
baos = null;
fos = null;
byte buf[] = new byte[32768];
int total_read = 0;
int size = compressed ? -1 : con.getContentLength();
baos = size <= 0 ? new ByteArrayOutputStream() : new ByteArrayOutputStream(size <= 0x40000 ? size : 0x40000);
do
{
if (cancel_download)
break;
int read = input_stream.read(buf);
if (read <= 0)
break;
if (total_read > 0x40000)
{
if (fos == null)
{
temp_file = AETemporaryFileHandler.createTempFile();
fos = new FileOutputStream(temp_file);
fos.write(baos.toByteArray());
baos = null;
}
fos.write(buf, 0, read);
} else
{
baos.write(buf, 0, read);
}
total_read += read;
informAmountComplete(total_read);
if (size > 0)
informPercentDone((100 * total_read) / size);
} while (true);
if (size > 0 && total_read != size)
if (total_read > size)
Debug.outNoStack((new StringBuilder()).append("Inconsistent stream length for '").append(trimForDisplay(original_url)).append("': expected = ").append(size).append(", actual = ").append(total_read).toString());
else
throw new IOException("Premature end of stream");
if (fos != null)
fos.close();
input_stream.close();
break MISSING_BLOCK_LABEL_1123;
Exception exception1;
exception1;
if (fos != null)
fos.close();
input_stream.close();
throw exception1;
InputStream res;
boolean handed_over;
if (temp_file != null)
{
res = new DeleteFileOnCloseInputStream(temp_file);
temp_file = null;
} else
{
res = new ByteArrayInputStream(baos.toByteArray());
}
handed_over = false;
if (!informComplete(res)) goto _L2; else goto _L1
_L1:
InputStream inputstream;
handed_over = true;
inputstream = res;
if (!handed_over)
res.close();
if (temp_file != null)
temp_file.delete();
if (auth_supplied)
SESecurityManager.setPasswordHandler(url, null);
return inputstream;
_L2:
if (!handed_over)
res.close();
break MISSING_BLOCK_LABEL_1242;
Exception exception2;
exception2;
if (!handed_over)
res.close();
throw exception2;
throw new ResourceDownloaderException((new StringBuilder()).append("Contents downloaded but rejected: '").append(trimForDisplay(original_url)).append("'").toString());
SSLException e;
e;
if (ssl_loop == 0 && SESecurityManager.installServerCertificates(url) != null)
{
if (temp_file != null)
temp_file.delete();
break MISSING_BLOCK_LABEL_1421;
}
throw e;
e;
if (ssl_loop != 0)
break MISSING_BLOCK_LABEL_1335;
use_compression = false;
if (temp_file != null)
temp_file.delete();
break MISSING_BLOCK_LABEL_1421;
if (temp_file != null)
temp_file.delete();
break MISSING_BLOCK_LABEL_1421;
e;
if (ssl_loop != 0)
break MISSING_BLOCK_LABEL_1402;
String msg = e.getMessage();
if (msg == null)
break MISSING_BLOCK_LABEL_1402;
msg = msg.toLowerCase();
if (msg.indexOf("gzip") == -1)
break MISSING_BLOCK_LABEL_1402;
use_compression = false;
if (temp_file != null)
temp_file.delete();
break MISSING_BLOCK_LABEL_1421;
throw e;
Exception exception3;
exception3;
if (temp_file != null)
temp_file.delete();
throw exception3;
ssl_loop++;
goto _L3
redirect_loop++;
goto _L4
throw new ResourceDownloaderException("Should never get here");
Exception exception4;
exception4;
if (auth_supplied)
SESecurityManager.setPasswordHandler(url, null);
throw exception4;
url;
throw new ResourceDownloaderException((new StringBuilder()).append("Exception while parsing URL '").append(trimForDisplay(original_url)).append("':").append(url.getMessage()).toString(), url);
url;
throw new ResourceDownloaderException((new StringBuilder()).append("Exception while initializing download of '").append(trimForDisplay(original_url)).append("': Unknown Host '").append(url.getMessage()).append("'").toString(), url);
url;
throw new ResourceDownloaderException((new StringBuilder()).append("I/O Exception while downloading '").append(trimForDisplay(original_url)).append("'").toString(), url);
url;
ResourceDownloaderException rde;
if (url instanceof ResourceDownloaderException)
rde = (ResourceDownloaderException)url;
else
rde = new ResourceDownloaderException("Unexpected error", url);
informFailed(rde);
throw rde;
}
public void cancel()
{
setCancelled();
cancel_download = true;
this_mon.enter();
if (input_stream != null)
try
{
input_stream.close();
}
catch (Throwable e) { }
this_mon.exit();
break MISSING_BLOCK_LABEL_54;
Exception exception;
exception;
this_mon.exit();
throw exception;
informFailed(new ResourceDownloaderCancelledException());
return;
}
protected void setRequestProperties(HttpURLConnection con, boolean use_compression)
{
Map properties = getLCKeyProperties();
Iterator it = properties.entrySet().iterator();
do
{
if (!it.hasNext())
break;
java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
String key = (String)entry.getKey();
Object value = entry.getValue();
if (key.startsWith("url_") && (value instanceof String))
{
key = key.substring(4);
if (!key.equals("accept-encoding") || use_compression)
con.setRequestProperty(key, (String)value);
}
} while (true);
}
protected void getRequestProperties(HttpURLConnection con)
{
try
{
setProperty("ContentType", con.getContentType());
setProperty("URL_URL", con.getURL());
Map headers = con.getHeaderFields();
Iterator it = headers.entrySet().iterator();
do
{
if (!it.hasNext())
break;
java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
String key = (String)entry.getKey();
Object val = entry.getValue();
if (key != null)
setProperty((new StringBuilder()).append("URL_").append(key).toString(), val);
} while (true);
setPropertiesSet();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
public PasswordAuthentication getAuthentication(String realm, URL tracker)
{
if (user_name == null || password == null)
{
String user_info = tracker.getUserInfo();
if (user_info == null)
return null;
String user_bit = user_info;
String pw_bit = "";
int pos = user_info.indexOf(':');
if (pos != -1)
{
user_bit = user_info.substring(0, pos);
pw_bit = user_info.substring(pos + 1);
}
return new PasswordAuthentication(user_bit, pw_bit.toCharArray());
} else
{
return new PasswordAuthentication(user_name, password.toCharArray());
}
}
public void setAuthenticationOutcome(String s, URL url, boolean flag)
{
}
public void clearPasswords()
{
}
private URLConnection openConnection(URL url)
throws IOException
{
if (force_no_proxy)
return Java15Utils.openConnectionForceNoProxy(url);
else
return url.openConnection();
}
protected String trimForDisplay(URL url)
{
String str = url.toString();
int pos = str.indexOf('?');
if (pos != -1)
str = str.substring(0, pos);
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -