{Transfers.remove(download.ID);}
// Fire the event with our transfer that contains Success = false
if (download.Callback != null)
{
try { download.Callback.execute(new AssetReceivedCallbackArgs(download, null)); }
catch (Exception ex) { JLogger.error(ex); }
}
return;
}
}
// This assumes that every transfer packet except the last one is exactly 1000 bytes,
// hopefully that is a safe assumption to make
try
{
byte[] bytes = new byte[asset.TransferData.Data.length];
Utils.arraycopy(asset.TransferData.Data, 0, bytes, 0, asset.TransferData.Data.length);
download.pmap.put(asset.TransferData.Packet, bytes);
download.Transferred += asset.TransferData.Data.length;
JLogger.debug(String.format("AssetManager: TransferPacketHandler: got asset %s packet length %d of packet no %d", download.AssetID.toString(), asset.TransferData.Data.length, asset.TransferData.Packet));
}
catch (IllegalArgumentException ex)
{
JLogger.error(String.format("TransferPacket handling failed. TransferData.Data.Length=%d, AssetData.Length=%d, TransferData.Packet=%d",
asset.TransferData.Data.length, download.AssetData.length, asset.TransferData.Packet));
return;
}
//Client.DebugLog(String.Format("Transfer packet {0}, received {1}/{2}/{3} bytes for asset {4}",
// asset.TransferData.Packet, asset.TransferData.Data.Length, transfer.Transferred, transfer.Size,
// transfer.AssetID.toString()));
// Check if we downloaded the full asset
if (download.Transferred >= download.Size)
{
int i =0;
for(Entry<Integer, byte[]> entry:download.pmap.entrySet())
{
Utils.arraycopy(entry.getValue(), 0, download.AssetData, i, entry.getValue().length);
i += entry.getValue().length;
}
download.pmap.clear();
JLogger.debug("Transfer for asset " + download.AssetID.toString() + " completed");
download.Success = true;
synchronized(Transfers)
{Transfers.remove(download.ID);}
// Cache successful asset download
Cache.saveAssetToCache(download.AssetID, download.AssetData);
if (download.Callback != null)
{
try { download.Callback.execute(new AssetReceivedCallbackArgs(download, WrapAsset(download))); }
catch (Exception ex) { JLogger.error(ex); }
}
}
}
}