File Download --- solution --- similar to 360 synchronization Client

Source: Internet
Author: User

Requirements:

In a file management activity, click an item to download the object;

Click All items to download the files corresponding to all items one by one.

When downloading an object, the page displays the download progress continuously.

The files on the server and local files use the same directory. The synchronization client at the root of 360 is similar.

Note:

1. A file is being downloaded, but the activity is destroyed. In this case, the file download operation is interrupted.

2. When you enter the file management activity again, you must determine whether a file is valid.

My Implementation ideas are as follows:

File management activity; downloadlooper thread for file download; detectsizelooper thread for local file size detection;

A data table, fileinofotable.

The four parts need to work together to complete the function.

Specific ideas:

1. When you enter the file management activity, check whether the fileinfotable exists. If not, create the data table.

2. when detecting whether a file is valid, use the item passed by the server to check whether the file exists locally. If yes, use the field serial number value in the item object (uniquely identifies a file) check fileinfotable to check whether the local file is valid. If it is valid, you do not need to download it. If it is invalid, you can delete it.

---------- Click a single file to download the implementation process ------------------------------------------

0. Start a downloadlogoff thread.

1. Get the item and send the download request to the downloadlooper thread. The downloadlogoff thread downloads data based on the information type.

2. The downloadlooper thread sends a message to detectsizelooper after the download is enabled and the file size to be downloaded is received.

Thread; and. Detectsizedlooper constantly checks the local file size, compares the file size to be downloaded, and sends update information to the file management activity to update the file download progress.

3. Before the downloadlogoff thread ends,Check the local file size, the size of the file to be downloaded, and the serial number of the file, and write it to fileinfotable. ---- The download is not completed and saved.

4. When the file management activity finds that the size of the local file is equal to the size of the file to be downloaded, two messages are sent to stop the detectsizeloading and downloadlooper threads;Save the file information to fileinfotable.

Other cases:

1). activity. When the system calls the ondestroy method, two messages are sent to the detectsizeloaders and downloadlooper threads to stop them.

---------- Click a single file to download the implementation process ------------------------------------------

--------- When multiple files are selected and multiple files are to be downloaded --------------------------------------------

0. Start a downloadlogoff thread.

1. Start a detectsizeloading thread.

2. Maintain a download queue and put all the items to be downloaded into the queue.

3. Get the item and send the download request to the downloadlooper thread. The downloadlogoff thread downloads data based on the information type.

4. The downloadlooper thread sends a message to detectsizelooper after the download is enabled and the file size to be downloaded is received.

Thread; and. Detectsizedlooper constantly checks the local file size, compares the file size to be downloaded, and sends update information to the file management activity to update the file download progress.

5. Before the downloadlogoff thread ends,Check the local file size, the size of the file to be downloaded, and the serial number of the file, and write it to fileinfotable. ---- The download is not completed and saved.


6. When a file management activity receives a message about the download completion of an object, it compares the size of the local file with the size of the file to be downloaded,If yes, save the information to fileinfotable.And remove the current item from the download queue, retrieve a new item, and repeat the above process again. If no queue is available, send the message and stop the downloadlooper thread and the detectsizelooper thread.

Other cases:

1). activity. When the system calls the ondestroy method, two messages are sent to the detectsizeloaders and downloadlooper threads to stop them.

--------- When multiple files are selected and multiple files are to be downloaded --------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.