|
@@ -3,7 +3,9 @@ package com.zskk.control;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
@@ -23,12 +25,16 @@ import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
|
|
|
import com.jfinal.plugin.druid.DruidPlugin;
|
|
|
import com.zskk.tools.XmlHelper;
|
|
|
|
|
|
+import okhttp3.Call;
|
|
|
+import okhttp3.Callback;
|
|
|
import okhttp3.FormBody;
|
|
|
+import okhttp3.Headers;
|
|
|
import okhttp3.MediaType;
|
|
|
import okhttp3.OkHttpClient;
|
|
|
import okhttp3.Request;
|
|
|
import okhttp3.RequestBody;
|
|
|
import okhttp3.Response;
|
|
|
+import okhttp3.ResponseBody;
|
|
|
|
|
|
public class ViewController extends Controller {
|
|
|
|
|
@@ -63,14 +69,37 @@ public class ViewController extends Controller {
|
|
|
|
|
|
public void downDcm() {
|
|
|
try {
|
|
|
- List<Record> d = Db.use("connected_dicom").find(this.getPara("sqlstr"));
|
|
|
- this.renderJson(d);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("http://10.0.25.99:81/MR/MRIMAGE2/1.2.392.200036.9116.4.2.9245.7569.3002/2")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ OKHTTP_CLIENT.newCall(request).enqueue(new Callback() {
|
|
|
+ @Override public void onFailure(Call call, IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override public void onResponse(Call call, Response response) throws IOException {
|
|
|
+ try (ResponseBody responseBody = response.body()) {
|
|
|
+ if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
+ writeFile(response);
|
|
|
+
|
|
|
+// Headers responseHeaders = response.headers();
|
|
|
+// for (int i = 0, size = responseHeaders.size(); i < size; i++) {
|
|
|
+// System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
|
|
|
+// }
|
|
|
+//
|
|
|
+// System.out.println(responseBody.string());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
} catch (Exception e) {
|
|
|
// TODO: handle exception
|
|
|
this.renderText(e.toString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public void testConn() {
|
|
|
try {
|
|
@@ -196,6 +225,47 @@ public class ViewController extends Controller {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void writeFile(Response response) {
|
|
|
+ InputStream is = null;
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ is = response.body().byteStream();
|
|
|
+ String path = "/home/lenovo/CFIND_XML";
|
|
|
+ File file = new File(path, "11");
|
|
|
+ try {
|
|
|
+ fos = new FileOutputStream(file);
|
|
|
+ byte[] bytes = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ //获取下载的文件的大小
|
|
|
+ long fileSize = response.body().contentLength();
|
|
|
+ long sum = 0;
|
|
|
+ int porSize = 0;
|
|
|
+ while ((len = is.read(bytes)) != -1) {
|
|
|
+ fos.write(bytes);
|
|
|
+ sum += len;
|
|
|
+ porSize = (int) ((sum * 1.0f / fileSize) * 100);
|
|
|
+// Message message = handler.obtainMessage(1);
|
|
|
+// message.arg1 = porSize;
|
|
|
+// handler.sendMessage(message);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (is != null) {
|
|
|
+ is.close();
|
|
|
+ }
|
|
|
+ if (fos != null) {
|
|
|
+ fos.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+// Log.i("myTag", "下载成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private String parseStringToDate() {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
Date date = new Date();
|