|
@@ -87,41 +87,38 @@ public class DownloadTask implements ITask {
|
|
|
}
|
|
|
|
|
|
private void writeFile(Response response, String uid) {
|
|
|
- InputStream is = null;
|
|
|
+ InputStream is = response.body().byteStream();;
|
|
|
FileOutputStream fos = null;
|
|
|
- is = response.body().byteStream();
|
|
|
String path = "/home/lenovo/CFIND_XML";
|
|
|
Random r = new Random();
|
|
|
Integer ran1 = r.nextInt(100000);
|
|
|
File file = new File(path, uid+ran1.toString());
|
|
|
try {
|
|
|
fos = new FileOutputStream(file);
|
|
|
- byte[] bytes = new byte[1024];
|
|
|
+ byte[] bytes = new byte[2048];
|
|
|
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);
|
|
|
- }
|
|
|
+// 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);
|
|
|
+// }
|
|
|
+ while (-1 != (len = is.read(bytes))) {
|
|
|
+ fos.write(bytes, 0, len);
|
|
|
+ }
|
|
|
+ fos.flush();
|
|
|
+ fos.close();
|
|
|
+ is.close();
|
|
|
+// file.renameTo(new File(path, uid+ran1.toString()+".dcm"));
|
|
|
+ File filentemp = new File(path, uid+ran1.toString());
|
|
|
+ File filen = new File(path, uid+ran1.toString()+".dcm");
|
|
|
+ filentemp.renameTo(filen);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- if (is != null) {
|
|
|
- is.close();
|
|
|
- }
|
|
|
- if (fos != null) {
|
|
|
- fos.close();
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
}
|
|
|
- file.renameTo(new File(path, uid+ran1.toString()+".dcm"));
|
|
|
|
|
|
}
|
|
|
|