while( it.hasNext()){
Map.Entry<DownloadManager, byte[]> entry = it.next();
DownloadManager download = entry.getKey();
try{
String hash = ByteFormatter.encodeString( download.getTorrent().getHash());
download_hashes += ( download_hashes.length()==0?"":"," ) + hash;
new_offline_downloads.put( hash, download );
}catch( Throwable e ){
log( download, "Failed to get download hash", e );
it.remove();
}
}
try{
String[] set_dl_results = service.setDownloads( client_id, download_hashes );
String set_dl_result = set_dl_results[0].trim();
String set_dl_status = set_dl_results[1];
if ( !set_dl_status.equals( "OK" )){
error_status = MessageText.getString( "device.od.error.opfailstatus", new String[]{ "SetDownloads", set_dl_status });
throw( new Exception( "Failing result returned: " + set_dl_status ));
}
String[] bits = Constants.PAT_SPLIT_COMMA.split(set_dl_result);
int num_bits = set_dl_result.length()==0?0:bits.length;
if ( num_bits != entries.size()){
log( "SetDownloads returned an invalid number of results (hashes=" + new_offline_downloads.size() + ",result=" + set_dl_result + ")");
}else{
it = entries.iterator();
int pos = 0;
while( it.hasNext()){
Map.Entry<DownloadManager, byte[]> entry = it.next();
DownloadManager download = entry.getKey();
try{
TOTorrent torrent = download.getTorrent();
String hash_str = ByteFormatter.encodeString( torrent.getHash());
int status = Integer.parseInt( bits[ pos++ ]);