/*
**FileSplitterFetch
*/
package NetFox;
import java
import
public class FileSplitterFetch extends Thread {
String sURL; //File URL
long nStartPos; //File Snippet Start Position
long nEndPos; //File Snippet End Position
int nThreadID; //Thread
boolean bDownOver = false; //Downing is over
boolean bStop = false; //Stop identical
FileAccessI fileAccessI = null; //File Access interface
public FileSplitterFetch(String sURL
{
this
this
this
nThreadID = id;
fileAccessI = new FileAccessI(sName
}
public void run()
{
while(nStartPos < nEndPos && !bStop)
{
try{
URL url = new URL(sURL);
HttpURLConnection httpConnection = (HttpURLConnection)url
(
String sProperty =
(
Utility
InputStream input = ();
//logResponseHead(httpConnection);
byte[] b = new byte[
int nRead;
while((nRead=input
{
nStartPos += fileAccessI
//if(nThreadID ==
// Utility
}
Utility
bDownOver = true;
//nPos = fileAccessI
}
catch(Exception e){e
}
}
//打印回應的頭信息
public void logResponseHead(HttpURLConnection con)
{
for(int i=
{
String header=con
if(header!=null)
//responseHeaders
Utility
else
break;
}
}
public void splitterStop()
{
bStop = true;
}
}
/*
**FileAccess
*/
package NetFox;
import java
public class FileAccessI implements Serializable{
RandomAccessFile oSavedFile;
long nPos;
public FileAccessI() throws IOException
{
this(
}
public FileAccessI(String sName
{
oSavedFile = new RandomAccessFile(sName
this
oSavedFile
}
public synchronized int write(byte[] b
{
int n =
try{
oSavedFile
n = nLen;
}
catch(IOException e)
{
e
}
return n;
}
}
/*
**SiteInfoBean
*/
package NetFox;
public class SiteInfoBean {
private String sSiteURL; //Site
private String sFilePath; //Saved File
private String sFileName; //Saved File
private int nSplitter; //Count of Splited Downloading File
public SiteInfoBean()
{
//default value of nSplitter is
this(
}
public SiteInfoBean(String sURL
{
sSiteURL= sURL;
sFilePath = sPath;
sFileName = sName;
this
}
public String getSSiteURL()
{
return sSiteURL;
}
public void setSSiteURL(String value)
{
sSiteURL = value;
}
public String getSFilePath()
{
return sFilePath;
}
public void setSFilePath(String value)
{
sFilePath = value;
}
public String getSFileName()
{
return sFileName;
}
public void setSFileName(String value)
{
sFileName = value;
}
public int getNSplitter()
{
return nSplitter;
}
public void setNSplitter(int nCount)
{
nSplitter = nCount;
}
}
/*
**Utility
*/
package NetFox;
public class Utility {
public Utility()
{
}
public static void sleep(int nSecond)
{
try{
Thread
}
catch(Exception e)
{
e
}
}
public static void log(String sMsg)
{
System
}
public static void log(int sMsg)
{
System
}
}
/*
**TestMethod
*/
package NetFox;
public class TestMethod {
public TestMethod()
{ ///xx/weblogic
try{
SiteInfoBean bean = new SiteInfoBean(
//SiteInfoBean bean = new SiteInfoBean(
SiteFileFetch fileFetch = new SiteFileFetch(bean);
fileFetch
}
catch(Exception e){e
}
}
public static void main(String[] args)
{
new TestMethod();
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26866.html