为了在我的应用程序中实现一个新模块,我一直在阅读Iteratees和Enumerators上的很多内容.
我现在正处于与第三方Java库集成的地步,并坚持使用此方法:
public Email addAttachment(String name, InputStream file) throws IOException {
this.attachments.put(name, file);
return this;
}
Run Code Online (Sandbox Code Playgroud)
我在我的API中拥有的是从WSHTTP调用返回的正文Enumerator[Array[Byte]].
我现在想知道如何编写一个Iteratee可以处理这个方法的块Array[Bytes]并创建一个InputStream.
(侧栏):该addAttachment方法还有其他版本,java.io.File但我希望避免在此操作中写入磁盘,而是宁愿处理流.
我试着从写这样的东西开始:
Iteratee.foreach[Array[Byte]] { bytes =>
???
}
Run Code Online (Sandbox Code Playgroud)
但是我不确定如何在InputStream这里与java进行交互.我找到了一个叫做a的东西,ByteArrayInputStream但它Array[Byte]在构造函数中占据了整体,我不确定在这个场景中是否可以工作,因为我正在使用块?
我可能需要一些Java帮助!
在此先感谢您的帮助.
新年快乐,首先!
我在Play中解析JSON时遇到了一些问题,我正在处理的格式如下:
JSON Response:
...
"image":{
"large":{
"path":"http://url.jpg",
"width":300,
"height":200
},
"medium":{
"path":"http://url.jpg",
"width":200,
"height":133
},
...
}
...
Run Code Online (Sandbox Code Playgroud)
我被大小坚持了.它们显然是变量,我不知道如何为此编写格式化程序?JSON来自外部服务.
到目前为止我有
final case class Foo(
..
..
image: Option[Image])
final case class Image(size: List[Size])
final case class Size(path: String, width: Int, height: Int)
Run Code Online (Sandbox Code Playgroud)
对于我刚刚Json.reads[x]为所有类进行的格式化.但是我很确定大小的变量会抛弃格式化,因为它无法从JSON中创建一个Image对象.
我在一个当前没有测试过的函数中有一个分支.它是来自request操作的错误处理程序(使用同名的节点模块).这是特定的行:
request(url, function (error, response, body) {
if (error) return cb(error);
Run Code Online (Sandbox Code Playgroud)
这是测试:
describe("handles errors", function() {
it("from the request", function (done) {
var api = nock('http://football-api.com')
.get('/api/?Action=today&APIKey=' + secrets.APIKey + '&comp_id=1204')
.reply(500);
fixture.getFixture(FixtureMock, function (err, fixture) {
expect(err).to.exist
done();
});
});
Run Code Online (Sandbox Code Playgroud)
规格失败:
Uncaught AssertionError: expected null to exist
Run Code Online (Sandbox Code Playgroud)
因此,将500状态代码作为没有正文的响应发送不会导致error请求回调,或者我正在测试错误的东西.