Methods Summary |
---|
public byte[] | downloadBytes(java.lang.Object downloadID, int requestSize)
if ( requestSize > getMaxDownloadChunkSize() )
{
trace( "Request too large: " + requestSize );
throw new IllegalArgumentException( "request too large: " + requestSize );
}
final DownloadInfo info = getDownloadInfo( downloadID );
final byte[] bytes = info.read( requestSize );
if ( info.isDone() )
{
trace( "download done: " + info.getID() );
staleDownloadCheck();
}
return( bytes );
|
private DownloadInfo | getDownloadInfo(java.lang.Object downloadID)
final DownloadInfo info = (DownloadInfo)mDownloadInfos.get( downloadID );
if ( info == null )
{
throw new IllegalArgumentException( "" + downloadID );
}
return( info );
|
public long | getDownloadLength(java.lang.Object downloadID)Get the total length the download will be, in bytes.
try
{
final DownloadInfo info = getDownloadInfo( downloadID );
return( info.getLength() );
}
catch( Exception e )
{
e.printStackTrace();
assert( false );
}
return( 0 );
|
public final java.lang.String | getGroup()
return( AMX.GROUP_UTILITY );
|
public int | getMaxDownloadChunkSize()
return( 5 * 1024 * 1024 );
|
public java.lang.Object | initiateDownload(java.io.File theFile, boolean deleteWhenDone)
//setTrace( true );
staleDownloadCheck();
final DownloadInfo info =
new DownloadInfo( mDownloadIDs.createID(), theFile, deleteWhenDone );
trace( "Created download info: " + info.getID() );
mDownloadInfos.put( info.getID(), info );
return( info.getID() );
|
public java.lang.Object | initiateUpload(java.lang.String name, long totalSize)
staleUploadCheck();
final String actualName = mangleUploadName( name );
final UploadInfo info = new UploadInfo( mUploadIDs.createID(), actualName, totalSize );
mUploadInfos.put( info.getID(), info );
return( info.getID() );
|
private java.lang.String | mangleUploadName(java.lang.String name)
String result = name;
if ( result != null )
{
result = result.replaceAll( "/", "_" );
result = result.replaceAll( "\\\\", "_" );
result = result.replaceAll( ":", "_" );
}
return( result );
|
private final void | staleDownloadCheck()Cleanup any downloads that have been accessed for a proscribed
amount of time given by DOWNLOAD_KEEP_ALIVE_MILLIS.
String[] keys = null;
synchronized( mDownloadInfos )
{
keys = GSetUtil.toStringArray( mDownloadInfos.keySet() );
}
// block other threads from trying to do the same stale check
synchronized( this )
{
for( int i = 0; i < keys.length; ++i )
{
final Object key = keys[ i ];
final DownloadInfo info = mDownloadInfos.get( key );
if ( info != null && info.isDone() )
{
mDownloadInfos.remove( key );
trace( "Cleaning up stale download: " + info.getID() +
"length was " + info.getLength() );
info.cleanup();
}
}
}
|
private final void | staleUploadCheck()Cleanup any threads that have been done for a proscribed
amount of time given by UPLOAD_KEEP_ALIVE_MILLIS.
String[] keys = null;
synchronized( mUploadInfos )
{
keys = GSetUtil.toStringArray( mUploadInfos.keySet() );
}
// block other threads from trying to do the same stale check
synchronized( this )
{
for( int i = 0; i < keys.length; ++i )
{
final Object key = keys[ i ];
final UploadInfo info = mUploadInfos.get( key );
if ( info != null && info.getMillisSinceLastAccess() > UPLOAD_KEEP_ALIVE_MILLIS )
{
trace( "Cleaning up stale upload: " + info.getID() );
mUploadInfos.remove( key );
info.cleanup();
}
}
}
|
public java.io.File | takeUpload(java.lang.Object uploadID)
// don't remove it until we find out it's done
final UploadInfo info = (UploadInfo)mUploadInfos.get( uploadID );
if ( info == null )
{
throw new IllegalArgumentException( "" + uploadID );
}
synchronized( info )
{
// by being synchronized, we can safely block any uploadBytes() activity
// while we check for it being done
if ( ! info.isDone() )
{
throw new IllegalArgumentException( "not done:" + uploadID );
}
mUploadInfos.remove( uploadID );
}
return( info.getFile() );
|
public boolean | uploadBytes(java.lang.Object uploadID, byte[] bytes)
final UploadInfo info = (UploadInfo)mUploadInfos.get( uploadID );
if ( info == null )
{
throw new IllegalArgumentException( "" + uploadID );
}
boolean done = false;
synchronized( info )
{
done = info.write( bytes );
}
return( done );
|