public List downloadFile(String id, String AppId, String cid){
//判断传入图像编码imgstr是否为空
if( StrUtil.isNullOrBlank(id)){
System.out.println("errorCode:"+"010200");
return null;
}
//判断传入文件名称fileName是否为空
if( StrUtil.isNullOrBlank(AppId)){
System.out.println("errorCode:"+"010200");
return null;
}
ITranslatAttributeService translatAttributeService = new TranslatAttributeService();
TranslatAttribute translatAttribute = new TranslatAttribute();
ArrayList pathList = new ArrayList();
ArrayList paths = new ArrayList();;
//查询数据库
List list = translatAttributeService.getObjectByUserId(id,cid);
if ((list != null) && (list.size() != 0)) {
for(int i=0;i<list.size();i++){
translatAttribute=(TranslatAttribute)list.get(i);
String path = translatAttribute.getImage_path();
if((path != null) && (path.length() != 0)){
pathList.add(path);
}else{
continue;
}
}
} else{
System.out.println("-----------当前无相关文件信息-----------");
return null;
}
//初始化转换文件流所需的变量
URL url;
HttpURLConnection conn = null;
byte[] data;
String base64Img;
String lines = null;
BufferedInputStream bis = null;
byte[] in_b = null;
byte[] buffer;
//判断取出的文件路径值
if ((pathList != null) && (pathList.size() != 0)) {
for(int i=0;i<pathList.size();i++){
//判断当前路径是否为空或null
String filePath = (String) pathList.get(i);
if(StrUtil.isNotNullOrBlank(filePath)){
try {
//创建URL对象
url = new URL(filePath);
//返回一个URLConnection对象,它表示到URL所引用的远程对象的连接
conn = (HttpURLConnection) url.openConnection();
//设定请求方式
conn.setRequestMethod("GET");
//建立到远程对象的实际连接
conn.connect();
//返回打开连接读取的输入流
InputStream in = conn.getInputStream();
// 取HTTP请求流长度
int size = conn.getContentLength();
// 用于缓存每次读取的数据
buffer = new byte[size];
// 用于存放结果的数组
in_b = new byte[size];
int count = 0;
int rbyte = 0;
// 循环读取
while (count < size){
// 每次实际读取长度存于rbyte中
rbyte = in.read(buffer);
for (int j = 0; j < rbyte; j++){
in_b[count + j] = buffer[j];
}
count += rbyte;
}
}catch (Exception e){
e.printStackTrace();
System.out.println("-----------当前转码异常-----------");
}
base64Img = new String(Base64.encodeBase64(in_b));
paths.add(base64Img);
}else{
System.out.println("-----------当前图片不存在-----------");
continue;
}
}
}else{
System.out.println("-----------当前无文件路径-----------");
return null;
}
return paths;
}
//判断传入图像编码imgstr是否为空
if( StrUtil.isNullOrBlank(id)){
System.out.println("errorCode:"+"010200");
return null;
}
//判断传入文件名称fileName是否为空
if( StrUtil.isNullOrBlank(AppId)){
System.out.println("errorCode:"+"010200");
return null;
}
ITranslatAttributeService translatAttributeService = new TranslatAttributeService();
TranslatAttribute translatAttribute = new TranslatAttribute();
ArrayList pathList = new ArrayList();
ArrayList paths = new ArrayList();;
//查询数据库
List list = translatAttributeService.getObjectByUserId(id,cid);
if ((list != null) && (list.size() != 0)) {
for(int i=0;i<list.size();i++){
translatAttribute=(TranslatAttribute)list.get(i);
String path = translatAttribute.getImage_path();
if((path != null) && (path.length() != 0)){
pathList.add(path);
}else{
continue;
}
}
} else{
System.out.println("-----------当前无相关文件信息-----------");
return null;
}
//初始化转换文件流所需的变量
URL url;
HttpURLConnection conn = null;
byte[] data;
String base64Img;
String lines = null;
BufferedInputStream bis = null;
byte[] in_b = null;
byte[] buffer;
//判断取出的文件路径值
if ((pathList != null) && (pathList.size() != 0)) {
for(int i=0;i<pathList.size();i++){
//判断当前路径是否为空或null
String filePath = (String) pathList.get(i);
if(StrUtil.isNotNullOrBlank(filePath)){
try {
//创建URL对象
url = new URL(filePath);
//返回一个URLConnection对象,它表示到URL所引用的远程对象的连接
conn = (HttpURLConnection) url.openConnection();
//设定请求方式
conn.setRequestMethod("GET");
//建立到远程对象的实际连接
conn.connect();
//返回打开连接读取的输入流
InputStream in = conn.getInputStream();
// 取HTTP请求流长度
int size = conn.getContentLength();
// 用于缓存每次读取的数据
buffer = new byte[size];
// 用于存放结果的数组
in_b = new byte[size];
int count = 0;
int rbyte = 0;
// 循环读取
while (count < size){
// 每次实际读取长度存于rbyte中
rbyte = in.read(buffer);
for (int j = 0; j < rbyte; j++){
in_b[count + j] = buffer[j];
}
count += rbyte;
}
}catch (Exception e){
e.printStackTrace();
System.out.println("-----------当前转码异常-----------");
}
base64Img = new String(Base64.encodeBase64(in_b));
paths.add(base64Img);
}else{
System.out.println("-----------当前图片不存在-----------");
continue;
}
}
}else{
System.out.println("-----------当前无文件路径-----------");
return null;
}
return paths;
}