当前位置: 网学 > 编程文档 > JAVA > 正文

用Java实现断点续传

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
ection);


byte b = new byte[1024];
int nRead;
while((nRead=input.read(b,0,1024)) > 0 && nStartPos < nEndPos && !bStop)
{
nStartPos += fileAccessI.write(b,0,nRead);
//if(nThreadID == 1)
// Utility.log("nStartPos = " + nStartPos + ", nEndPos = " + nEndPos);
}


Utility.log("Thread " + nThreadID + " is over!");
bDownOver = true;
//nPos = fileAccessI.write (b,0,nRead);
}
catch(Exception e){e.printStackTrace ();}
}
}


//打印回应的头信息
public void logResponseHead(HttpURLConnection con)
{
for(int i=1;;i++)
{
String header=con.getHeaderFieldKey(i);
if(header!=null)
//responseHeaders.put(header,httpConnection.getHeaderField(header));
Utility.log(header+" : "+con.getHeaderField(header));
else
break;
}
}


public void splitterStop()
{
bStop = true;
}


}


/*
**FileAccess.java
*/
package NetFox;
import java.io.*;


public class FileAccessI implements Serializable{


RandomAccessFile oSavedFile;
long nPos;


public FileAccessI() throws IOException
{
this("",0);
}


public FileAccessI(String sName,long nPos) throws IOException
{
oSavedFile = new RandomAccessFile(sName,"rw");
this.nPos = nPos;
oSavedFile.seek(nPos);
}


public synchronized int write(byte b,int nStart,int nLen)
{
int n = -1;
try{
oSavedFile.write(b,nStart,nLen);
n = nLen;
}
catch(IOException e)
{
e.printStackTrace ();
}


return n;
}


}


/*
**SiteInfoBean.java
*/
package NetFox;


public class SiteInfoBean {


private String sSiteURL; //Site''s URL
private String sFilePath; //Saved File''s Path
private String sFileName; //Saved File''s Name
private int nSplitter; //Count of Splited Downloading File


public SiteInfoBean()
{
//default value of nSplitter is 5
this("","","",5);
}


public SiteInfoBean(String sURL,String sPath,String sName,int nSpiltter)
{
sSiteURL= sURL;
sFilePath = sPath;
sFileName = sName;
this.nSplitter = nSpiltter;


}


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.java
*/
package NetFox;


public class Utility {


public Utility()
{


}


public static void sleep(int nSecond)
{
try{
Thread.sleep(nSecond);
}
catch(Exception e)
{
e.printStackTrace ();
}
}


public static void log(String sMsg)
{
System.err.println(sMsg);
}


public static void log(int sMsg)
{
System.err.println(sMsg);
}
}


/*
**TestMethod.java
*/
package NetFox;


public class TestMethod {


public TestMethod()
{ ///xx/weblogic60b2_win.exe
try{
SiteInfoBean bean = new SiteInfoBean("http://localhost/xx/weblogic60b2_win.exe","L:\\temp","weblogic60b2_win.exe",5);
//SiteInfoBean bean = new SiteInfoBean("http://localhost:8080/down.zip","L:\\temp","weblogic60b2_win.exe",5);
SiteFileFetch fileFetch = new SiteFileFetch(bean);
fileFetch.star

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号