📄 urlfetcher.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2008-6-16 11:25:41
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: URLFetcher.java
package com.eightmotions.util;
import java.io.*;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
// Referenced classes of package com.eightmotions.util:
// NotifyLoadURL, UtilMidp
public class URLFetcher
implements Runnable
{
public URLFetcher(String in_url)
{
m_res = new StringBuffer();
m_fetchOk = false;
m_ref = null;
m_method = "GET";
m_url = in_url;
}
public void setMethod(String inMethod)
{
m_method = inMethod;
}
public void setUserNamePassword(String inUsername, String inPassword)
{
m_userName = inUsername;
m_password = inPassword;
}
public void fetch()
{
Thread t = new Thread(this);
t.start();
}
public static HttpConnection open(String url)
throws IOException
{
if(appendUrl != null)
if(url.indexOf('?') == -1)
url = url + "?" + appendUrl;
else
url = url + "&" + appendUrl;
return (HttpConnection)Connector.open(url);
}
public void setListener(NotifyLoadURL inRef)
{
m_ref = inRef;
}
public void run()
{
HttpConnection cnx;
InputStream is;
String url;
Exception e;
cnx = null;
is = null;
url = m_url;
try
{
if(m_url.startsWith("res:"))
{
if(m_ref != null)
try
{
is = getClass().getResourceAsStream(m_url.substring(4));
m_ref.inputStream(is, null);
}
// Misplaced declaration of an exception variable
catch(Exception e1)
{
e1.printStackTrace();
m_ref.error(-1);
}
// break MISSING_BLOCK_LABEL_788;
}
int status;
status = -1;
for(int nbredirects = 0; nbredirects++ < 10;)
{
UtilMidp.addInfo("URL:" + url);
cnx = open(url);
cnx.setRequestMethod(m_method);
if(m_userName != null)
{
String credential = encode64(m_userName + ":" + m_password);
cnx.setRequestProperty("Authorization", "Basic " + credential);
}
status = cnx.getResponseCode();
String type = cnx.getType();
// cnx;
if(status != 307)
{
// cnx;
if(status != 302)
{
// cnx;
if(status != 301)
break;
}
}
url = cnx.getHeaderField("Location");
if(!url.startsWith("http://"))
url = "http://" + cnx.getHost() + url;
cnx.close();
UtilMidp.addInfo("Status:" + status + " Redirecting to " + url);
}
// cnx;
// if(status == 200)
// break MISSING_BLOCK_LABEL_453;
// m_res.append("Error:" + status);
// if(m_ref == null)
// break MISSING_BLOCK_LABEL_420;
m_ref.error(status);
if(is != null)
is.close();
if(cnx != null)
cnx.close();
}
catch(Exception e2)
{
e2.printStackTrace();
}
// return;
// throw new IOException("Response status not OK [" + status + "]");
try
{
ByteArrayOutputStream bo;
is = cnx.openInputStream();
// if(m_ref != null && !m_ref.inputStream(is, cnx))
// break MISSING_BLOCK_LABEL_663;
bo = new ByteArrayOutputStream();
//_L1:
String line;
boolean cont;
int ch;
do
{
if((ch = is.read()) == -1);
// break MISSING_BLOCK_LABEL_613;
bo.write(ch);
} while((char)ch != '\n');
line = new String(bo.toByteArray(), "UTF-8");
// if(m_ref == null)
// break MISSING_BLOCK_LABEL_587;
cont = m_ref.lineRead(this, line);
if(!cont)
{
try
{
if(is != null)
is.close();
if(cnx != null)
cnx.close();
}
catch(Exception e3)
{
e3.printStackTrace();
}
return;
}
bo.reset();
m_res.append(line);
System.out.println(line);
// goto _L1
m_res.append(new String(bo.toByteArray(), "UTF-8"));
UtilMidp.addInfo("\nLu:" + m_res.toString());
try
{
if(is != null)
is.close();
if(cnx != null)
cnx.close();
}
// Misplaced declaration of an exception variable
catch(Exception e4)
{
e4.printStackTrace();
}
// break MISSING_BLOCK_LABEL_770;
// status;
// status.printStackTrace();
// UtilMidp.showException(status);
try
{
if(is != null)
is.close();
if(cnx != null)
cnx.close();
}
// Misplaced declaration of an exception variable
catch(Exception es)
{
es.printStackTrace();
}
// break MISSING_BLOCK_LABEL_770;
// Exception exception;
// exception;
try
{
if(is != null)
is.close();
if(cnx != null)
cnx.close();
}
catch(Exception e6)
{
e6.printStackTrace();
}
// throw exception;
if(m_ref != null)
m_ref.loaded(this);
return;
}catch(Exception e4)
{
e4.printStackTrace();
}
}
public static String encode64(byte data[])
{
return encode64(data, 0, data.length, null).toString();
}
public static String encode64(String str)
{
return encode64(str.getBytes());
}
public static StringBuffer encode64(byte data[], int start, int len, StringBuffer buf)
{
if(buf == null)
buf = new StringBuffer((data.length * 3) / 2);
int end = len - 3;
int i = start;
int n = 0;
do
{
if(i > end)
break;
int d = (data[i] & 0xff) << 16 | (data[i + 1] & 0xff) << 8 | data[i + 2] & 0xff;
buf.append(charTab[d >> 18 & 0x3f]);
buf.append(charTab[d >> 12 & 0x3f]);
buf.append(charTab[d >> 6 & 0x3f]);
buf.append(charTab[d & 0x3f]);
i += 3;
if(n++ >= 14)
{
n = 0;
buf.append("\r\n");
}
} while(true);
if(i == (start + len) - 2)
{
int d = (data[i] & 0xff) << 16 | (data[i + 1] & 0xff) << 8;
buf.append(charTab[d >> 18 & 0x3f]);
buf.append(charTab[d >> 12 & 0x3f]);
buf.append(charTab[d >> 6 & 0x3f]);
buf.append("=");
} else
if(i == (start + len) - 1)
{
int d = (data[i] & 0xff) << 16;
buf.append(charTab[d >> 18 & 0x3f]);
buf.append(charTab[d >> 12 & 0x3f]);
buf.append("==");
}
return buf;
}
public StringBuffer m_res;
private String m_url;
boolean m_fetchOk;
NotifyLoadURL m_ref;
private String m_userName;
private String m_password;
private String m_method;
public static String appendUrl = null;
static final char charTab[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -