java的http断点续传原理(二)
来源:优易学  2011-12-11 17:10:41   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  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;

  }

上一页  [1] [2] [3] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训