|
@@ -1,6 +1,10 @@
|
|
package com.zskk.control;
|
|
package com.zskk.control;
|
|
|
|
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -75,6 +79,53 @@ public class ViewController extends Controller {
|
|
return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
|
|
return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static String getFileWithUrl(String url, String filename) {
|
|
|
|
+
|
|
|
|
+ Request request = new Request.Builder().url(url).build();
|
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
|
+ if (!response.isSuccessful())
|
|
|
|
+ throw new IOException("Unexpected code " + response);
|
|
|
|
+ InputStream inputStream = response.body().source().inputStream();
|
|
|
|
+ // 本地文件夹目录(下载位置)
|
|
|
|
+ String folder = PropKit.get("oss_localPath");
|
|
|
|
+ // 下载文件保存位置
|
|
|
|
+ String savepath = folder + "/" + filename;
|
|
|
|
+ BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savepath)));
|
|
|
|
+ byte[] data = new byte[1024];
|
|
|
|
+ int len;
|
|
|
|
+ int available = inputStream.available();
|
|
|
|
+ while ((len = inputStream.read(data)) != -1) {
|
|
|
|
+ bufferedOutputStream.write(data, 0, len);
|
|
|
|
+ }
|
|
|
|
+ bufferedOutputStream.flush();
|
|
|
|
+ bufferedOutputStream.close();
|
|
|
|
+ inputStream.close();
|
|
|
|
+
|
|
|
|
+ return savepath;
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return e.toString();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void testdld() {
|
|
|
|
+ try {
|
|
|
|
+ String filePath = "http://200.200.200.163:8090/X-0-202208261038400267000310351.PNG";
|
|
|
|
+ String fileNameStr[] = filePath.split("/");
|
|
|
|
+ String fileName = fileNameStr[fileNameStr.length - 1];
|
|
|
|
+ String fileStorePath = getFileWithUrl(filePath, fileName);
|
|
|
|
+ renderText(fileStorePath);
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // TODO: handle exception
|
|
|
|
+ renderText(e.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* post请求
|
|
* post请求
|
|
* @param url-请求地址
|
|
* @param url-请求地址
|