?? wapptr.java~351~
字號:
markflg.Setval(0);
WriteLog(LogFileName);
} catch (IllegalStateException ex) {
} catch (SocketException ex) {
} catch (FileNotFoundException ex) {
/** @todo Handle this exception */
} catch (IOException ex) {
/** @todo Handle this exception */
}
if (xhtml_wml == 1) {
http_disconnect();
} else {
disconnect();
}
return ret;
}
/**
* WriteLog
*/
public void WriteLog(String LogFname) throws FileNotFoundException,
IOException {
Calendar ca = Calendar.getInstance();
Date dt = new Date();
ca.setTime(dt);
String dstr = new String(String.valueOf(ca.get(Calendar.YEAR)));
dstr = dstr + ca.get(Calendar.MONTH) + ca.get(Calendar.DAY_OF_MONTH) +
ca.get(Calendar.HOUR) + ca.get(Calendar.MINUTE) +
ca.get(Calendar.SECOND);
//String currentdir = System.getProperty("user.dir");
String logfile = LogFname;
FileWriter fw = new FileWriter(logfile, true);
PrintWriter out = new PrintWriter(fw);
String logData = "";
int len = LogStr.length;
for (int i = 0; i < LogStr.length; i++) {
if (i == len - 1) {
logData += LogStr[i];
} else {
logData += LogStr[i] + "\t";
}
}
out.println(logData);
out.close();
fw.close();
}
/**
* DecodeWbxml
*
* @param WbxmlFileName String
*/
public boolean DecodeWbxml(String WbxmlFileName) {
boolean ret = false;
// Decode the bytes in WBXML file to get wml file
System.out.println("開始解碼:" + WbxmlFileName);
FileInputStream tokenStream;
String wmlfilename = WbxmlFileName.substring(0,
WbxmlFileName.lastIndexOf(".")) + ".wml";
try {
tokenStream = new FileInputStream(WbxmlFileName);
FileOutputStream xmlStream = new FileOutputStream(wmlfilename);
Document document = WBXMLDecoder.getInstance().decode(tokenStream);
OutputFormat of = new OutputFormat(document);
XMLSerializer serial = new XMLSerializer(xmlStream, of);
serial.setOutputByteStream(xmlStream);
serial.setOutputFormat(of);
serial.asDOMSerializer();
serial.serialize(document);
xmlStream.close();
tokenStream.close();
ret = true;
System.out.println("解碼結束:" + wmlfilename);
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
/**
* InitHost
*
* @param IniFile String
*/
public void InitHost(String IniFile) {
FileWork m_fw = new FileWork();
Vector tempVector = new Vector();
int hostflg = 0;
String oneline = new String("");
try {
m_fw.FW_ReadFile(IniFile, tempVector);
for (int i = 0; i < tempVector.size(); i++) {
oneline = tempVector.elementAt(i).toString();
String[] StrArry = oneline.split("\\|");
if (StrArry[0].equals("0")) {
hostflg = 1;
int c = StrArry[1].indexOf(':');
if (c > 0) {
gwAddr = InetAddress.getByName(StrArry[1].substring(0,
c));
gwPort = Integer.parseInt(StrArry[1].substring(c + 1));
} else {
gwAddr = InetAddress.getByName(StrArry[1]);
gwPort = 9201;
}
}
}
} catch (IOException ex) {
ex.printStackTrace();
log.error("WapPtr 讀取網關失敗");
}
if (hostflg == 0) {
log.error("WapPtr 讀取網關失敗");
}
}
/**
* SetLinkGate
*
* @param anInt int
*/
public void SetLinkGate(String flag) {
if (flag.equals("0")) {
linkgate = 0;
} else {
linkgate = 1;
}
}
/**
* CheckJar
*/
public int CheckJar(byte[] payload) {
int ret = 1;
int flag = 0;
String str = new String(payload);
String sb = str.toUpperCase();
int pos1 = sb.indexOf("<!DOCTYPE");
if (pos1 >= 0) {
flag = 1;
int pos2 = sb.indexOf(">", pos1);
if (pos2 > pos1) {
String txt = sb.substring(pos1, pos2 + 1);
int pos3 = txt.indexOf("HTMLL 4.01");
int pos4 = txt.indexOf("XHTML");
if (pos3 >= 0 || pos4 >= 0) {
flag = 1;
}
}
} else {
int pos51 = sb.indexOf("HTML");
if (pos51 >= 0) {
flag = 1;
}
}
if (flag == 1) {
ret = 0;
} else {
InputStream tokenStream = new ByteArrayInputStream(payload);
if ((WBXMLDecoder.getInstance().decodeFowChk(tokenStream)) == 0) {
ret = 0;
} else {
ret = 1;
}
}
//System.out.println(str);
return ret;
}
/**
* GetUrlFile
*/
public boolean GetUrlFile(String m_url, String LogFileName) {
boolean ret = false;
int RetCode = 0;
long BegMillisTims = 0;
long EndMillisTims = 0;
if (m_url.equals("")) {
return false;
}
int mIndex = 0;
String TempUrl = m_url;
String TempUrl2 = "";
FileType = "html";
if (downmms == 1) {
} else {
mIndex = TempUrl.lastIndexOf(".");
if (mIndex != -1) {
String tempFile1ow = TempUrl.substring(mIndex + 1);
String tempFile = tempFile1ow.toUpperCase();
if (tempFile.equals("GIF") || tempFile.equals("JPG") ||
tempFile.equals("BMP") ||
tempFile.equals("WBMP") || tempFile.equals("PNG") ||
tempFile.equals("AMR") || tempFile.equals("WAV") ||
tempFile.equals("MID") || tempFile.equals("MP3") ||
tempFile.equals("RM") ||
tempFile.equals("JAR") || tempFile.equals("WAR") ||
tempFile.equals("JAD")) {
FileType = tempFile;
} else {
int ps = tempFile.indexOf("JAR");
int ps1 = tempFile.indexOf("WAR");
int ps2 = tempFile.indexOf("JAD");
if (ps >= 0) {
FileType = "JAR";
} else if (ps1 >= 0) {
FileType = "WAR";
} else if (ps2 >= 0) {
FileType = "JAD";
} else {
}
}
} else {
FileType = "html";
}
}
upperlayerhttp = new UpperLayerHttp();
http_url = new Hurl(upperlayerhttp, m_url);
http_url.start();
BegMillisTims = System.currentTimeMillis();
LogStr[0] = Long.toString(BegMillisTims).substring(0, 10);
LogStr[1] = Long.toString(BegMillisTims).substring(10);
LogStr[2] = "100";
LogStr[7] = "0";
LogStr[8] = "0";
try {
WriteLog(LogFileName);
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
int code = -1;
int count = 0;
if (httpwaitForCp(DEFAULT_HTTP_TIMEOUT) == 1) {
ret = false;
} else {
ret = true;
}
EndMillisTims = System.currentTimeMillis();
LogStr[0] = Long.toString(EndMillisTims).substring(0, 10);
LogStr[1] = Long.toString(EndMillisTims).substring(10);
LogStr[7] = Long.toString(EndMillisTims - BegMillisTims);
if (ret) {
LogStr[8] = Integer.toString(32);
LogStr[2] = "105";
System.out.println("下載成功");
} else {
LogStr[8] = Integer.toString(500);
LogStr[2] = "107";
System.out.println("下載失敗");
}
return ret;
}
private int httpwaitForCp(long timeout) {
int ret = 0;
long startAt = 0;
int first = 0;
if (timeout > 0) {
startAt = System.currentTimeMillis();
} while (http_url != null) {
if (waitfor == 1) {
ret = 0;
break;
}
if (waitfor == 2) {
ret = 1;
waitfor = 0;
break;
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
if (first == 1) {
startAt = markflg.Getbagflg();
}
first = 1;
if (timeout > 0 && (startAt + timeout) < System.currentTimeMillis()) {
log.debug("Timeout occurred");
System.out.println("Timeout occurred");
ret = 1;
break;
}
}
//ret=1;
return ret;
}
private void writehttpfile(byte[] poly) {
String dstr, htmlfile;
htmlfile = "";
System.out.println("writing to a file");
Calendar ca = Calendar.getInstance();
Date dt = new Date();
ca.setTime(dt);
dstr = new String(String.valueOf(ca.get(Calendar.YEAR)));
dstr = dstr + ca.get(Calendar.MONTH) + ca.get(Calendar.DAY_OF_MONTH) +
ca.get(Calendar.HOUR) + ca.get(Calendar.MINUTE) +
ca.get(Calendar.SECOND);
String currentdir = System.getProperty("user.dir");
if (FileType.equals("html") || FileType.equals("") ||
FileType.equals("null")) {
LogStr[11] = "df" + dstr + ".html";
htmlfile = currentdir + "\\df" + dstr + ".html";
} else {
LogStr[11] = "df" + dstr + "." + FileType;
htmlfile = currentdir + "\\df" + dstr + "." + FileType;
}
try {
FileOutputStream wapContent = new FileOutputStream(htmlfile);
wapContent.write(poly);
wapContent.close();
} catch (Exception exp) {
//exp.printStackTrace();
System.out.println("寫文件失敗");
System.exit(1);
}
waitfor = 1;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -