package com.js.ai.modules.pointwall.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.js.ai.common.utils.StringUtils;
import com.js.ai.common.web.BaseController;
/**
*
* @ClassName: DownImgAction2
* @Description: 客户端图片下载接口
* @author:
* @date:
*/
@Controller
@RequestMapping(value = "${adminPath}/client")
public class DownImgAction2 extends BaseController {
private static Logger logger = Logger.getLogger(DownImgAction2.class);
@RequestMapping(value = "downImg")
@ResponseBody
public void downImg(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
response.setContentType("image/*");
HashMap<String, Object> map=new HashMap<String,Object>();
String imgUrl = request.getParameter("imageUrl");//获取客户端发送的图片下载路径
if(StringUtils.isNotBlank(imgUrl)){
String rootPath = request.getSession().getServletContext().getRealPath(File.separator);
File file = new File(rootPath + imgUrl);
if (file.isFile()) {//文件存在
System.out.println(rootPath + imgUrl);
FileInputStream inputStream = new FileInputStream(file);
OutputStream outputStream = response.getOutputStream();
try {
int count = 0;
byte[] buffer = new byte[1024];
while ((count = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, count);
}
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}else {
logger.info("图片下载路径不存在!");
map.put("error", "图片下载路径不存在!");
}
}
}

  

package com.js.ai.modules.pointwall.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.fop.cli.Main;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import com.js.ai.common.utils.StringUtils;
import com.js.ai.common.web.BaseController;
import com.js.ai.modules.pointwall.entity.PointwallSystemVersons;
import com.js.ai.modules.pointwall.service.PointwallSystemVersonsService;
import com.js.ai.modules.pointwall.util.JsonHandle; /**
*
* @ClassName: ApkDownloadAction
* @Description: 客户端Apk下载接口
* @author:
* @date:
*/
@Controller
@RequestMapping(value = "${adminPath}/client")
public class ApkDownloadAction2 extends BaseController {
private static Logger logger = Logger.getLogger(ApkDownloadAction2.class);
/**
*
* @Title: apkDownload
* @Description: TODO 更新最新版本
* @param request
* @param response
* @throws IOException
* @return: void
*/
@RequestMapping(value = "apkDownload")
@ResponseBody
public void apkDownload(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
HashMap<String, Object> map=new HashMap<String,Object>();
String versionsUrl =request.getParameter("versionsUrl");//获取客户端发送的版本路径
if(StringUtils.isNotBlank(versionsUrl)){
String rootPath=request.getSession().getServletContext().getRealPath(File.separator);
File file=new File(rootPath+versionsUrl);
if(file.isFile()){//文件存在
System.out.println(rootPath + versionsUrl);
FileInputStream inputStream = new FileInputStream(file);
OutputStream outputStream = response.getOutputStream();
try {
int count = 0;
byte[] buffer = new byte[1024];
while ((count = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, count);
}
outputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}else {
logger.info("版本路径不存在!");
map.put("error", "版本路径不存在!");
}
}
}

  

最新文章

  1. 动态加载js和css
  2. C++ 用于大型程序的工具
  3. div+css基础
  4. [GIF] GIF Loop Coder Single Mode
  5. UrlPathEncode与UrlEncode的区别
  6. fedora 解决yumBackend.py进程CPU占用过高
  7. Java 字节数组类型(byte[])与int类型互转
  8. GitHub上可能用到的开源
  9. 如何有效地配置基于Spring的应用系统
  10. 【CDH篇】---CDH从初识到搭建到应用
  11. Azure架构(一):云计算基础
  12. [Codeforces178F2]Representative Sampling
  13. 转:ArcGIS中利用ArcMap将地理坐标系转换成投影坐标系(从WKID=4326到WKID=102100)
  14. CSS-3 新弹性盒模型属性
  15. IOS应用发布NSLog的注释及使用重定向,把控制台内容写入文件
  16. Docker Swarm——集群管理
  17. 利用webbrowser自动查取地点坐标
  18. 【转】SWFUpload使用指南
  19. java中Map转化为bean
  20. OSG-获取OSG的源代码和第三方库并编译

热门文章

  1. Jexus部署Asp.Net Core项目
  2. python 爬虫003-正则表达式简单介绍
  3. SmsUtils 发送短信
  4. 【lightoj-1046】Rider(BFS)
  5. docker 国内加速器配置
  6. Android中SQLite介绍
  7. 对无序数组的并发搜索的java实现
  8. 【python】numpy pandas 特性(随时更新)
  9. tcp 服务端和客户端程序设计
  10. JMX心得 -- Server端