zoukankan      html  css  js  c++  java
  • 给安卓端调用的apk、图片下载接口

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

      

  • 相关阅读:
    tomcat的systemctl启动脚本
    vmware中虚拟化的问题
    zabbix-3.4.14源码安装
    tomcat启动后8005端口未被占用
    Centos7初始化脚本
    CentOS7.3上如何安装Apache/2.4.34
    js完整教程一 : 基本概念和数组操作
    浅入浅出Lambda表达式
    这些基础却重要的面向对象概念,你还记得多少
    MVC5+EF6 入门完整教程11--细说MVC中仓储模式的应用
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6802245.html
Copyright © 2011-2022 走看看