当前位置: 首页>>代码示例>>Java>>正文


Java DownloadInterruptedError类代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:jluisred,项目名称:HotSpots,代码行数:18,代码来源:RetryWrap.java

示例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;
}
 
开发者ID:jluisred,项目名称:HotSpots,代码行数:9,代码来源:VGet.java

示例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());
}
 
开发者ID:jluisred,项目名称:HotSpots,代码行数:10,代码来源:RetryWrap.java

示例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;
}
 
开发者ID:jluisred,项目名称:HotSpots,代码行数:20,代码来源:DirectMultipart.java

示例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();
    }
}
 
开发者ID:jluisred,项目名称:HotSpots,代码行数:60,代码来源:DirectRange.java

示例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();
    }
}
 
开发者ID:jluisred,项目名称:HotSpots,代码行数:47,代码来源:DirectSingle.java


注:本文中的com.github.axet.wget.info.ex.DownloadInterruptedError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。