zoukankan      html  css  js  c++  java
  • 开放通知接口,执行文件同步操作

    View Code
    package me.xuzs.sso.web.servlet;
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URL;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class UpdateStaticResource extends HttpServlet {
    
        private static final long serialVersionUID = 1L;
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            String updateFile = req.getParameter("updateFile");
            String saveFile = "d:/" + updateFile;
            if(!processUpdate(updateFile, saveFile)){
                // log
            }
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            super.doPost(req, resp);
        }
    
        @Override
        public void init() throws ServletException {
            super.init();
        }
        
        private boolean processUpdate(String url, String downloadFile){
            // TODO 此处读取OM地址
            String fullUrl = "http://xuzs-host.xuzs.com" + url;
            int bytesum = 0;
            int byteread = 0;  
            InputStream inStream = null;
            FileOutputStream fos = null;
            try {
                URL fileUrl = new URL(fullUrl);
                inStream = fileUrl.openStream();
                fos = new FileOutputStream(downloadFile);
                File file = new File(downloadFile);
                if(!file.exists()){
                    file.createNewFile();
                }
                byte[] buffer = new byte[1204];
                while ((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread; 
    //                System.out.println(bytesum);
                    
                    fos.write(buffer, 0, byteread);
                }
                return true;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            } finally {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            
        }
    
    }
  • 相关阅读:
    罗马数字转换成整数
    整数转换成罗马数字
    hdu 5050 大数
    hdu 5051 找规律?+大trick
    hdu 5055
    hdu 5054
    hdu 5058 set应用
    hdu 5056 所有字母数都<=k的子串数目
    hdu 5059 简单字符串处理
    hdu 5060 五种情况求圆柱体与球体交
  • 原文地址:https://www.cnblogs.com/xzs603/p/2994605.html
Copyright © 2011-2022 走看看