zoukankan      html  css  js  c++  java
  • 图片地址中转

    // 图片文件中转接口
    @RequestMapping(value = "/images/{guid}", method = { RequestMethod.GET })
    public void getIcon(@PathVariable("guid") String guid, HttpServletRequest request, HttpServletResponse response)
    throws IOException {
    URL url = new URL(ImgAddressUtils.URL_imgAddress + guid + "?isView=false");
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setRequestMethod("GET");
    urlConnection.connect();
    System.out.println("Connection Response From Test Servlet");
    InputStream inputStream = urlConnection.getInputStream();
    // 响应
    response.setContentType("image/png");
    OutputStream stream = response.getOutputStream();
    stream.write(input2byte(inputStream));
    stream.flush();
    stream.close();
    }
    public static final byte[] input2byte(InputStream inStream) throws IOException {
    ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
    byte[] buff = new byte[10240];
    int rc = 0;
    while ((rc = inStream.read(buff, 0, 10240)) > 0) {
    swapStream.write(buff, 0, rc);
    }
    byte[] in2b = swapStream.toByteArray();
    return in2b;
    }
  • 相关阅读:
    Linux搭建www,mail,ftp三大DNS服务器
    linux基本命令
    Vmware网络不可达
    CentOS7基本配置一
    https
    阶段02JavaWeb基础day04mysql
    阶段02JavaWeb基础day02&03JavaScript
    阶段02JavaWeb基础day01html&css
    io复用select方法编写的服务器
    for循环 底层工作原理
  • 原文地址:https://www.cnblogs.com/Logan626/p/6006723.html
Copyright © 2011-2022 走看看