//啟動子線程
fileSplitterFetch = new FileSplitterFetch[nStartPos
for(int i=
{
fileSplitterFetch[i] = new FileSplitterFetch(siteInfoBean
siteInfoBean
nStartPos[i]
Utility
fileSplitterFetch[i]
}
// fileSplitterFetch[nPos
siteInfoBean
// Utility
nEndPos =
// fileSplitterFetch[nPos
//等待子線程結束
//int count =
//是否結束while循環
boolean breakWhile = false;
while(!bStop)
{
write_nPos();
Utility
breakWhile = true;
for(int i=
{
if(!fileSplitterFetch[i]
{
breakWhile = false;
break;
}
}
if(breakWhile)
break;
//count++;
//if(count>
// siteStop();
}
System
}
catch(Exception e){e
}
//獲得文件長度
public long getFileSize()
{
int nFileLength =
try{
URL url = new URL(siteInfoBean
HttpURLConnection httpConnection = (HttpURLConnection)url
(
int responseCode=();
if(responseCode>=
{
processErrorCode(responseCode);
return
}
String sHeader;
for(int i=
{
//DataInputStream in = new DataInputStream( ());
//Utility
sHeader=(i);
if(sHeader!=null)
{
if(sHeader
{
nFileLength = Integer
break;
}
}
else
break;
}
}
catch(IOException e){e
catch(Exception e){e
Utility
return nFileLength;
}
//保存下載信息(文件指針位置)
private void write_nPos()
{
try{
output = new DataOutputStream(new FileOutputStream(tmpFile));
output
for(int i=
{
// output
output
output
}
output
}
catch(IOException e){e
catch(Exception e){e
}
//讀取保存的下載信息(文件指針位置)
private void read_nPos()
{
try{
DataInputStream input = new DataInputStream(new FileInputStream(tmpFile));
int nCount = input
nStartPos = new long[nCount];
nEndPos = new long[nCount];
for(int i=
{
nStartPos[i] = input
nEndPos[i] = input
}
input
}
catch(IOException e){e
catch(Exception e){e
}
private void processErrorCode(int nErrorCode)
{
System
}
//停止文件下載
public void siteStop()
{
bStop = true;
for(int i=
fileSplitterFetch[i]
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27070.html