本文整理汇总了Java中com.github.axet.wget.info.ex.DownloadInterruptedError类的典型用法代码示例。如果您正苦于以下问题:Java DownloadInterruptedError类的具体用法?Java DownloadInterruptedError怎么用?Java DownloadInterruptedError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DownloadInterruptedError类属于com.github.axet.wget.info.ex包,在下文中一共展示了DownloadInterruptedError类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retry
import com.github.axet.wget.info.ex.DownloadInterruptedError; //导入依赖的package包/类
static <T> void retry(AtomicBoolean stop, WrapReturn<T> r, RuntimeException e) {
for (int i = RETRY_DELAY; i >= 0; i--) {
r.retry(i, e);
if (stop.get())
throw new DownloadInterruptedError("stop");
if (Thread.currentThread().isInterrupted())
throw new DownloadInterruptedError("interrrupted");
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
throw new DownloadInterruptedError(e1);
}
}
}
示例2: done
import com.github.axet.wget.info.ex.DownloadInterruptedError; //导入依赖的package包/类
boolean done(AtomicBoolean stop) {
if (stop.get())
throw new DownloadInterruptedError("stop");
if (Thread.currentThread().isInterrupted())
throw new DownloadInterruptedError("interrupted");
return false;
}
示例3: moved
import com.github.axet.wget.info.ex.DownloadInterruptedError; //导入依赖的package包/类
static <T> void moved(AtomicBoolean stop, WrapReturn<T> r, DownloadMoved e) {
if (stop.get())
throw new DownloadInterruptedError("stop");
if (Thread.currentThread().isInterrupted())
throw new DownloadInterruptedError("interrrupted");
r.moved(e.getMoved());
}
示例4: done
import com.github.axet.wget.info.ex.DownloadInterruptedError; //导入依赖的package包/类
/**
* return true, when thread pool empty, and here is no unfinished parts to
* download
*
* @return true - done. false - not done yet
* @throws InterruptedException
*/
boolean done(AtomicBoolean stop) {
if (stop.get())
throw new DownloadInterruptedError("stop");
if (Thread.interrupted())
throw new DownloadInterruptedError("interupted");
if (worker.active())
return false;
if (getPart() != null)
return false;
return true;
}
示例5: downloadPart
import com.github.axet.wget.info.ex.DownloadInterruptedError; //导入依赖的package包/类
public void downloadPart(DownloadInfo info, AtomicBoolean stop, Runnable notify) throws IOException {
RandomAccessFile fos = null;
BufferedInputStream binaryreader = null;
try {
URL url = info.getSource();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(CONNECT_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
conn.setRequestProperty("User-Agent", info.getUserAgent());
if (info.getReferer() != null)
conn.setRequestProperty("Referer", info.getReferer().toExternalForm());
File f = target;
if (!f.exists())
f.createNewFile();
info.setCount(FileUtils.sizeOf(f));
if (info.getCount() >= info.getLength()) {
notify.run();
return;
}
fos = new RandomAccessFile(f, "rw");
if (info.getCount() > 0) {
conn.setRequestProperty("Range", "bytes=" + info.getCount() + "-");
fos.seek(info.getCount());
}
byte[] bytes = new byte[BUF_SIZE];
int read = 0;
RetryWrap.check(conn);
binaryreader = new BufferedInputStream(conn.getInputStream());
while ((read = binaryreader.read(bytes)) > 0) {
fos.write(bytes, 0, read);
info.setCount(info.getCount() + read);
notify.run();
if (stop.get())
throw new DownloadInterruptedError("stop");
if (Thread.interrupted())
throw new DownloadInterruptedError("interrupted");
}
} finally {
if (fos != null)
fos.close();
if (binaryreader != null)
binaryreader.close();
}
}
示例6: downloadPart
import com.github.axet.wget.info.ex.DownloadInterruptedError; //导入依赖的package包/类
void downloadPart(DownloadInfo info, AtomicBoolean stop, Runnable notify) throws IOException {
RandomAccessFile fos = null;
try {
URL url = info.getSource();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(CONNECT_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
conn.setRequestProperty("User-Agent", info.getUserAgent());
if (info.getReferer() != null)
conn.setRequestProperty("Referer", info.getReferer().toExternalForm());
File f = target;
info.setCount(0);
f.createNewFile();
fos = new RandomAccessFile(f, "rw");
byte[] bytes = new byte[BUF_SIZE];
int read = 0;
RetryWrap.check(conn);
BufferedInputStream binaryreader = new BufferedInputStream(conn.getInputStream());
while ((read = binaryreader.read(bytes)) > 0) {
fos.write(bytes, 0, read);
info.setCount(info.getCount() + read);
notify.run();
if (stop.get())
throw new DownloadInterruptedError("stop");
if (Thread.interrupted())
throw new DownloadInterruptedError("interrupted");
}
binaryreader.close();
} finally {
if (fos != null)
fos.close();
}
}