xuannth / MoverAlert-CMS

0 stars 0 forks source link

Download File #1

Open Jacobvu84 opened 3 years ago

Jacobvu84 commented 3 years ago
import java.io.File;
import java.util.List;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Splitter;

public class. WaitForDownloadFile{

    public static void completed(String nameFile) {

        File tempFile = new File(System.getProperty("user.dir") + "/" + nameFile);

        DateTime actualDateTime = new DateTime();
        DateTime timeout = actualDateTime.plusMinutes(15);

        int current=0;

        while (current != timeout.getSecondOfDay()) {
            if(tempFile.exists()) { 
                LOGGER.info("The Downloading is Completed! ");
                break;
            }
            current = new DateTime().getSecondOfDay();
        }
    }

}
Jacobvu84 commented 3 years ago

Cách dùng

WaitForDownloadFile.completed("abc.xlsx")

xuannth commented 3 years ago

Em đã chạy thử đoạn code ở trên và có một số câu hỏi như sau ạ:

  1. Em đã import logger như code của thầy nhưng nó vẫn báo lỗi chưa tạo class LOGGER
  2. Em đã tự tạo class LOGGER (chỉ có phương thức print) để chạy thì đến phần download xong thì page ko làm gì tiếp theo, làm sao để mình biết là file của mình đã đc download xong ạ? ( em đoán là do cái LOGGER em chưa làm đúng) hay phải đợi 15p sau thì trình duyệt mới close ạ ( cái này em chưa check thử )
  3. Thầy giải thích giúp e các ý nghĩa các dòng code này đc ko ạ? DateTime actualDateTime = new DateTime(); DateTime timeout = actualDateTime.plusMinutes(15); while (current != timeout.getSecondOfDay()) current = new DateTime().getSecondOfDay();