前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Cloud Feign接口返回流

Spring Cloud Feign接口返回流

作者头像
java干货
发布2021-02-19 11:08:42
1.9K0
发布2021-02-19 11:08:42
举报
文章被收录于专栏:java干货

身无彩凤双飞翼,心有灵犀一点通。

https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/java/java16.jpg
https://raw.githubusercontent.com/longfeizheng/longfeizheng.github.io/master/images/java/java16.jpg

服务提供者

代码语言:javascript
复制
@GetMapping("/{id}")
    public void queryJobInfoLogDetail(@PathVariable("id") Long id, HttpServletResponse response) {

        File file = new File("xxxxx");
        InputStream fileInputStream = new FileInputStream(file);
        OutputStream outStream;
        try {
            outStream = response.getOutputStream();

            byte[] bytes = new byte[1024];
            int len = 0;
            while ((len = fileInputStream.read(bytes)) != -1) {
                outStream.write(bytes, 0, len);
            }
            fileInputStream.close();
            outStream.close();
            outStream.flush();
        } catch (IOException e) {
            log.error("exception", e);
        }
    }

client 客户端

代码语言:javascript
复制
@GetMapping(value = "/{id}", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    feign.Response queryJobInfoLogDetail(@PathVariable("id") Long id);

服务消费者

代码语言:javascript
复制
    @GetMapping("/{id}")
    public void queryJobInfoLogInfoList(@PathVariable("id") Long id, HttpServletResponse servletResponse) {

        Response response = apiServices.queryJobInfoLogDetail(id);
        Response.Body body = response.body();

        InputStream fileInputStream = null;
        OutputStream outStream;
        try {
            fileInputStream = body.asInputStream();
            outStream = servletResponse.getOutputStream();

            byte[] bytes = new byte[1024];
            int len = 0;
            while ((len = fileInputStream.read(bytes)) != -1) {
                outStream.write(bytes, 0, len);
            }
            fileInputStream.close();
            outStream.close();
            outStream.flush();
        } catch (Exception e) {

        }
    
 
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/10/12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 服务提供者
  • client 客户端
  • 服务消费者
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档