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));
}
}
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);
}
Aggregations