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;
    }
  • 相关阅读:
    Queue
    List
    面试1
    野指针和空指针
    指针的定义和使用
    多文件编程
    函数声明
    函数样式
    字符串比较
    函数的定义和使用
  • 原文地址:https://www.cnblogs.com/Logan626/p/6006723.html
Copyright © 2011-2022 走看看