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", "版本路径不存在!"); } } }