2023年3月9日16:19:22
parent
1755c45ac3
commit
71aece0cbf
|
|
@ -57,6 +57,8 @@ public class HttpDownLoadController {
|
|||
|
||||
private final SimpleObjectProperty<File> file_target = new SimpleObjectProperty<>();
|
||||
|
||||
private static final int DEFAULT_BUFFER_SIZE = 8192;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
|
|
@ -83,6 +85,8 @@ public class HttpDownLoadController {
|
|||
return;
|
||||
}
|
||||
|
||||
download_info.setText(null);
|
||||
|
||||
MyService myService = new MyService();
|
||||
myService.progressProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue.doubleValue() >= 1){
|
||||
|
|
@ -110,9 +114,9 @@ public class HttpDownLoadController {
|
|||
|
||||
@Override
|
||||
protected Task<Number> createTask() {
|
||||
return new Task<Number>() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
protected Number call(){
|
||||
protected Number call() {
|
||||
int size = 0;
|
||||
try {
|
||||
URL url1 = new URL(url.getText());
|
||||
|
|
@ -121,10 +125,9 @@ public class HttpDownLoadController {
|
|||
if (size < 0) {
|
||||
download_info.appendText("无法获取文件大小。");
|
||||
download_info.appendText(System.lineSeparator());
|
||||
}else{
|
||||
download_info.appendText("文件大小为:" + size + " bytes");
|
||||
} else {
|
||||
download_info.appendText("文件大小为:" + FileUtil.readableFileSize(size));
|
||||
download_info.appendText(System.lineSeparator());
|
||||
|
||||
String fileName;
|
||||
final String path = url.getText();
|
||||
// 从路径中获取文件名
|
||||
|
|
@ -134,34 +137,21 @@ public class HttpDownLoadController {
|
|||
fileName = URLUtil.encodeQuery(path, CharsetUtil.CHARSET_UTF_8);
|
||||
}
|
||||
String pathText = download_path.getText();
|
||||
|
||||
InputStream fis = conn.getInputStream();
|
||||
int max = size;
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(new File(pathText + "/" + fileName));
|
||||
|
||||
byte[] bytes = new byte[100000];
|
||||
|
||||
int i = 0;
|
||||
|
||||
double sum = 0 ;
|
||||
|
||||
double progress = 0;
|
||||
byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
|
||||
int i;
|
||||
double sum = 0;
|
||||
double progress = 0;
|
||||
this.updateMessage("开始下载:-------->" + pathText + "/" + fileName);
|
||||
while ((i = fis.read(bytes, 0, bytes.length)) != -1) {
|
||||
|
||||
if (this.isCancelled()){
|
||||
while ((i = fis.read(bytes, 0, DEFAULT_BUFFER_SIZE)) != -1) {
|
||||
if (this.isCancelled()) {
|
||||
break;
|
||||
}
|
||||
|
||||
fos.write(bytes,0,i);
|
||||
|
||||
fos.write(bytes, 0, i);
|
||||
sum = sum + i;
|
||||
|
||||
this.updateProgress(sum,max);
|
||||
|
||||
progress = sum /max;
|
||||
|
||||
this.updateProgress(sum, size);
|
||||
progress = sum / size;
|
||||
this.updateMessage("已下载:" + FileUtil.readableFileSize((long) sum));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
package com.zhangmeng.tools.utils;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
|
|
@ -41,6 +43,10 @@ public class ResourcesUtils {
|
|||
return ResourcesUtils.class.getResource(path);
|
||||
}
|
||||
|
||||
public static Image getBg(){
|
||||
return new Image(ImagePath.path(ImagePath.ImagePathType.BACKGROUND_IMAGE));
|
||||
}
|
||||
|
||||
public enum Menu{
|
||||
Md5("md5加密",0),
|
||||
SpringSecurity("spring加密",1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue