States: RUNNING, PAUSED, COMPLETED, FAILED, CANCELED.
COMPLETED, FAILED, and CANCELED are terminal states.RUNNING and PAUSED are active states.FileDownloaderLibrary(int totalMemory, int maxConcurrentDownloads)
maxConcurrentDownloads >= 1. RUNNING and PAUSED downloads are active.COMPLETED, FAILED, and CANCELED downloads are inactive.totalMemory is the maximum sum of characters currently stored in memory across all active downloads.boolean createDownload(String downloadId, int chunksCount, int fileSize)
chunksCount chunks in parallel.0 to chunksCount - 1.fileSize is the total number of characters expected in the final file.RUNNING state with 0 downloaded characters.String downloadText(String downloadId, int chunkId, String text)
text to the specified chunk of the given download.downloadId.fileSize, the download immediately becomes COMPLETED.fileSize, the download becomes FAILED with error FILE_TOO_LARGE.NO_MEMORY and the new text is not appended.INACTIVE_DOWNLOAD."state=RUNNING,progress=50,error=".boolean pauseDownload(String downloadId)
RUNNING state.true if paused successfully, otherwise returns false.boolean resumeDownload(String downloadId)
PAUSED state.true if resumed successfully, otherwise returns false.boolean cancelDownload(String downloadId)
CANCELED state.true if canceled successfully, otherwise returns false if downloadId doesn't exists or download is already inactive.String getDownloadStatus(String downloadId)
"state=RUNNING,progress=42,error=,downloadedChars=42,totalChars=100"downloadId, return: "state=NOT_FOUND,progress=0,error=DOWNLOAD_NOT_FOUND,downloadedChars=0,totalChars=0"FileDownloaderLibrary(totalMemory=20, maxConcurrentDownloads=2) → library initializedcreateDownload(downloadId="DL-1", chunksCount=2, fileSize=10) → truegetDownloadStatus(downloadId="DL-1") → "state=RUNNING,progress=0,error=,downloadedChars=0,totalChars=10"downloadText(downloadId="DL-1", chunkId=2, text="x") → "state=RUNNING,progress=0,error=INVALID_CHUNK_ID"downloadText(downloadId="DL-1", chunkId=0, text="hello") → "state=RUNNING,progress=50,error="downloadText(downloadId="DL-1", chunkId=1, text="world") → "state=COMPLETED,progress=100,error="getDownloadStatus(downloadId="DL-1") → "state=COMPLETED,progress=100,error=,downloadedChars=10,totalChars=10"downloadText(downloadId="DL-1", chunkId=0, text="!") → "state=COMPLETED,progress=100,error=INACTIVE_DOWNLOAD"cancelDownload(downloadId="DL-1") → falseFileDownloaderLibrary(totalMemory=30, maxConcurrentDownloads=2) → library initializedcreateDownload(downloadId="DL-2", chunksCount=3, fileSize=12) → truedownloadText(downloadId="DL-2", chunkId=0, text="abcd") → "state=RUNNING,progress=33,error="pauseDownload(downloadId="DL-2") → truedownloadText(downloadId="DL-2", chunkId=1, text="ef") → "state=PAUSED,progress=33,error=DOWNLOAD_PAUSED"getDownloadStatus(downloadId="DL-2") → "state=PAUSED,progress=33,error=,downloadedChars=4,totalChars=12"resumeDownload(downloadId="DL-2") → truedownloadText(downloadId="DL-2", chunkId=1, text="efgh") → "state=RUNNING,progress=66,error="cancelDownload(downloadId="DL-2") → truegetDownloadStatus(downloadId="DL-2") → "state=CANCELED,progress=66,error=,downloadedChars=8,totalChars=12"resumeDownload(downloadId="DL-2") → falsegetDownloadStatus(downloadId="UNKNOWN") → "state=NOT_FOUND,progress=0,error=DOWNLOAD_NOT_FOUND,downloadedChars=0,totalChars=0"FileDownloaderLibrary(totalMemory=10, maxConcurrentDownloads=2) → library initializedcreateDownload(downloadId="DL-3", chunksCount=2, fileSize=5) → truecreateDownload(downloadId="DL-4", chunksCount=1, fileSize=6) → truecreateDownload(downloadId="DL-5", chunksCount=1, fileSize=7) → falsedownloadText(downloadId="DL-3", chunkId=0, text="abc") → "state=RUNNING,progress=60,error="downloadText(downloadId="DL-4", chunkId=0, text="wxyz") → "state=RUNNING,progress=66,error="downloadText(downloadId="DL-3", chunkId=1, text="def") → "state=FAILED,progress=60,error=FILE_TOO_LARGE"getDownloadStatus(downloadId="DL-3") → "state=FAILED,progress=60,error=FILE_TOO_LARGE,downloadedChars=3,totalChars=5"createDownload(downloadId="DL-5", chunksCount=1, fileSize=7) → truedownloadText(downloadId="DL-5", chunkId=0, text="1234567") → "state=RUNNING,progress=0,error=NO_MEMORY"cancelDownload(downloadId="DL-4") → truedownloadText(downloadId="DL-5", chunkId=0, text="1234567") → "state=COMPLETED,progress=100,error="getDownloadStatus(downloadId="DL-5") → "state=COMPLETED,progress=100,error=,downloadedChars=7,totalChars=7"