Methods Summary |
---|
public void | asyncDownload()
try{
this_mon.enter();
if ( cancelled ){
done_sem.release();
informFailed((ResourceDownloaderException)result);
}else{
done_count++;
current_downloader = current_delegate.getClone( this );
informActivity( getLogIndent() + "Downloading: " + getName());
current_downloader.addListener( this );
current_downloader.asyncDownload();
}
}finally{
this_mon.exit();
}
|
public void | cancel()
setCancelled();
try{
this_mon.enter();
result = new ResourceDownloaderException( "Download cancelled");
cancelled = true;
informFailed((ResourceDownloaderException)result );
done_sem.release();
if ( current_downloader != null ){
current_downloader.cancel();
}
}finally{
this_mon.exit();
}
|
public boolean | completed(ResourceDownloader downloader, java.io.InputStream data)
boolean complete = false;
try{
if ( done_count == 1 ){
// assumption is that there is a refresh tag
boolean marked = false;
if ( data instanceof ByteArrayInputStream){
data.mark(data.available());
marked = true;
}
// leave file open if marked so we can recover
HTMLPage page = HTMLPageFactory.loadPage( data, !marked );
URL redirect = page.getMetaRefreshURL();
if ( redirect == null ){
if ( !marked ){
failed( downloader, new ResourceDownloaderException( "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("meta-refresh processing fails", e ));
}
return( true );
|
public java.io.InputStream | download()
asyncDownload();
done_sem.reserve();
if ( result instanceof InputStream ){
return((InputStream)result);
}
throw((ResourceDownloaderException)result);
|
public void | failed(ResourceDownloader downloader, ResourceDownloaderException e)
result = e;
done_sem.release();
informFailed(e);
|
public ResourceDownloaderBaseImpl | getClone(ResourceDownloaderBaseImpl parent)
ResourceDownloaderMetaRefreshImpl c = new ResourceDownloaderMetaRefreshImpl( parent, delegate.getClone( this ));
c.setSize( size );
c.setProperties( this );
return( c );
|
public java.lang.String | getName()
return( delegate.getName() + ": meta-refresh" );
|
public long | getSize()
if ( size == -2 ){
try{
size = getSizeSupport();
}finally{
if ( size == -2 ){
size = -1;
}
setSize( size );
}
}
return( size );
|
protected long | getSizeSupport()
try{
ResourceDownloader x = delegate.getClone( this );
addReportListener( x );
HTMLPage page = HTMLPageFactory.loadPage( x.download());
URL redirect = page.getMetaRefreshURL();
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( "getSize failed", e ));
}
|
protected void | setProperty(java.lang.String name, java.lang.Object value)
setPropertySupport( name, value );
delegate.setProperty( name, value );
|
protected void | setSize(long l)
size = l;
if ( size >= 0 ){
delegate.setSize( size );
}
|