Search in sources :

Example 1 with HTMLPage

use of com.biglybt.core.html.HTMLPage in project BiglyBT by BiglySoftware.

the class ResourceDownloaderMetaRefreshImpl method getSizeSupport.

protected long getSizeSupport() throws ResourceDownloaderException {
    try {
        ResourceDownloader x = delegate.getClone(this);
        addReportListener(x);
        HTMLPage page = HTMLPageFactory.loadPage(x.download());
        URL base_url = (URL) x.getProperty("URL_URL");
        URL redirect = page.getMetaRefreshURL(base_url);
        if (redirect == null) {
            ResourceDownloaderBaseImpl c = delegate.getClone(this);
            addReportListener(c);
            long res = c.getSize();
            setProperties(c);
            return (res);
        } else {
            ResourceDownloaderURLImpl c = new ResourceDownloaderURLImpl(getParent(), redirect);
            addReportListener(c);
            long res = c.getSize();
            setProperties(c);
            return (res);
        }
    } catch (HTMLException e) {
        throw (new ResourceDownloaderException(this, "getSize failed", e));
    }
}
Also used : HTMLPage(com.biglybt.core.html.HTMLPage) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) HTMLException(com.biglybt.core.html.HTMLException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL)

Example 2 with HTMLPage

use of com.biglybt.core.html.HTMLPage in project BiglyBT by BiglySoftware.

the class ResourceDownloaderMetaRefreshImpl method completed.

@Override
public boolean completed(ResourceDownloader downloader, InputStream data) {
    boolean complete = false;
    try {
        if (done_count == 1) {
            // assumption is that there is a refresh tag
            boolean marked = false;
            if (data.markSupported()) {
                data.mark(data.available());
                marked = true;
            }
            // leave file open if marked so we can recover
            HTMLPage page = HTMLPageFactory.loadPage(data, !marked);
            URL base_url = (URL) downloader.getProperty("URL_URL");
            URL redirect = page.getMetaRefreshURL(base_url);
            if (redirect == null) {
                if (!marked) {
                    failed(downloader, new ResourceDownloaderException(this, "meta refresh tag not found and input stream not recoverable"));
                } else {
                    data.reset();
                    complete = true;
                }
            } else {
                current_delegate = new ResourceDownloaderURLImpl(this, redirect);
                // informActivity( "meta-refresh -> " + current_delegate.getName());
                asyncDownload();
            }
            if (marked && !complete) {
                data.close();
            }
        } else {
            complete = true;
        }
        if (complete) {
            if (informComplete(data)) {
                result = data;
                done_sem.release();
            }
        }
    } catch (Throwable e) {
        failed(downloader, new ResourceDownloaderException(this, "meta-refresh processing fails", e));
    }
    return (true);
}
Also used : HTMLPage(com.biglybt.core.html.HTMLPage) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) URL(java.net.URL)

Aggregations

HTMLPage (com.biglybt.core.html.HTMLPage)2 ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)2 URL (java.net.URL)2 HTMLException (com.biglybt.core.html.HTMLException)1 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)1