|
@@ -16,7 +16,7 @@ import com.jcraft.jsch.ChannelSftp;
|
|
|
import com.jcraft.jsch.JSch;
|
|
|
import com.jcraft.jsch.Session;
|
|
|
import nckd.base.helper.CommonHelperUtils;
|
|
|
-import java.util.Properties;
|
|
|
+
|
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
@@ -48,7 +48,7 @@ public class AttachmentFileUtil {
|
|
|
Map<String, Object> attachItem = new HashMap<>();
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
attachItem.put("name", fileName);
|
|
|
- attachItem.put("uid", uid1);
|
|
|
+ attachItem.put("uid", getUid());
|
|
|
InputStream inputStream = null;
|
|
|
ByteArrayOutputStream outStream = null;
|
|
|
String tempUrl = null;
|
|
@@ -83,24 +83,24 @@ public class AttachmentFileUtil {
|
|
|
logger.info("FTP inputStream -- size:"+inputStream.available());
|
|
|
System.out.println("inputStream:"+inputStream);
|
|
|
|
|
|
- outStream = new ByteArrayOutputStream();
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
- int len = 0;
|
|
|
- while( (len = inputStream.read(buffer)) != -1 ){
|
|
|
- outStream.write(buffer, 0, len);
|
|
|
- }
|
|
|
- byte[] bt = outStream.toByteArray();
|
|
|
+ // outStream = new ByteArrayOutputStream();
|
|
|
+ // byte[] buffer = new byte[1024];
|
|
|
+ // int len = 0;
|
|
|
+ // while( (len = inputStream.read(buffer)) != -1 ){
|
|
|
+ // outStream.write(buffer, 0, len);
|
|
|
+ // }
|
|
|
+ // byte[] bt = outStream.toByteArray();
|
|
|
|
|
|
- if(null != bt && bt.length > 0){
|
|
|
- DecimalFormat df = new DecimalFormat("#");
|
|
|
- size = Integer.parseInt(df.format((double) bt.length));
|
|
|
+ // if(null != bt && bt.length > 0){
|
|
|
+ // DecimalFormat df = new DecimalFormat("#");
|
|
|
+ // size = Integer.parseInt(df.format((double) bt.length));
|
|
|
|
|
|
- System.out.println("文件大小=:" + size);
|
|
|
- }else{
|
|
|
- System.out.println("没有从该连接获得内容");
|
|
|
- }
|
|
|
+ // System.out.println("文件大小=:" + size);
|
|
|
+ // }else{
|
|
|
+ // System.out.println("没有从该连接获得内容");
|
|
|
+ // }
|
|
|
|
|
|
- attachItem.put("size", size);
|
|
|
+ // attachItem.put("size", size);
|
|
|
// 苍穹自带
|
|
|
TempFileCache cache = CacheFactory.getCommonCacheFactory().getTempFileCache();
|
|
|
tempUrl = cache.saveAsFullUrl((String) attachItem.get("name"), inputStream, 1600);
|
|
@@ -305,6 +305,15 @@ public class AttachmentFileUtil {
|
|
|
return b.toString();
|
|
|
}
|
|
|
|
|
|
+ public static StringBuilder getUid() {
|
|
|
+ StringBuilder uid = new StringBuilder("rc-upload-");
|
|
|
+ uid.append((new Date()).getTime());
|
|
|
+ uid.append("-");
|
|
|
+ int index = (int) (1.0D + Math.random() * 10.0D);
|
|
|
+ uid.append(index);
|
|
|
+ return uid;
|
|
|
+ }
|
|
|
+
|
|
|
public static void downloadFile(String fileUrl, String saveDir) throws IOException {
|
|
|
URL url = new URL(fileUrl);
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|