栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

ChunkedInput在球衣中不起作用

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ChunkedInput在球衣中不起作用

格式球衣文档:

用ChunkedOutput编写块很简单,您只需调用方法write()即可将一个块恰好写入输出。通过输入读数,它会稍微复杂一些。除非开发人员告知,否则ChunkedInput不知道如何区分字节流中的块。为了定义自定义的块边界,ChunkedInput提供了注册ChunkParser的可能性,该块从输入流中读取块并将它们分开。Jersey提供了几种块解析器实现,并且您可以根据需要实现自己的解析器来分离块。在上面的示例中,
使用Jersey 提供的默认解析器,该解析器 根据 r n分隔字符序列的存在来分隔块

因此,您的服务器必须使用 r n分隔多个块,或者您必须注册ChunkParser。

假设您有一个常量完成每个块,您可以尝试:

Client client = ClientBuilder.newClient();//2 is to increase amount of data and 3(seconds) is for time b/w chunked output  ,can be changed        final Response response = client.target("http://jerseyexample-ravikant.rhcloud.com/rest/jws/streaming/2/3").request()     .get();        final ChunkedInput<String> chunkedInput = response.readEntity(new GenericType<ChunkedInput<String>>() {        });        chunkedInput.setParser(ChunkedInput.createParser(BOUNDARY));        String chunk;        while ((chunk = chunkedInput.read()) != null) { System.err.println("Next chunk received: " ); System.out.println(chunk);        }

而BOUNDARY是每个块的终结字符串。您编辑中的in.readLine解决方案将按每个换行符分解“块”,即使一个块包含 n,也将被解释为2个块。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/506426.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号