Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6b3d5f1b
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6b3d5f1b
编写于
6月 23, 2016
作者:
S
Sebastien Deleuze
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Turn FlushingDataBuffer to an empty DataBuffer
上级
3c80c19c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
23 deletion
+28
-23
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java
...rg/springframework/core/io/buffer/FlushingDataBuffer.java
+8
-9
spring-web-reactive/src/main/java/org/springframework/http/codec/SseEventEncoder.java
.../java/org/springframework/http/codec/SseEventEncoder.java
+2
-1
spring-web-reactive/src/test/java/org/springframework/core/codec/support/SseEventEncoderTests.java
...ingframework/core/codec/support/SseEventEncoderTests.java
+13
-9
spring-web-reactive/src/test/java/org/springframework/http/server/reactive/FlushingIntegrationTests.java
...mework/http/server/reactive/FlushingIntegrationTests.java
+5
-4
未找到文件。
spring-web-reactive/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java
浏览文件 @
6b3d5f1b
...
@@ -21,26 +21,25 @@ import java.io.OutputStream;
...
@@ -21,26 +21,25 @@ import java.io.OutputStream;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.function.IntPredicate
;
import
java.util.function.IntPredicate
;
import
org.springframework.util.Assert
;
/**
/**
*
{@link DataBuffer} wrapper that indicates the file or the socket writing this buffer
*
Empty {@link DataBuffer} that indicates to the file or the socket writing it that
* should be flushed.
*
previously buffered data
should be flushed.
*
*
* @author Sebastien Deleuze
* @author Sebastien Deleuze
* @see FlushingDataBuffer#INSTANCE
*/
*/
public
class
FlushingDataBuffer
implements
DataBuffer
{
public
class
FlushingDataBuffer
implements
DataBuffer
{
/** Singleton instance of this class */
public
static
final
FlushingDataBuffer
INSTANCE
=
new
FlushingDataBuffer
();
private
final
DataBuffer
buffer
;
private
final
DataBuffer
buffer
;
public
FlushingDataBuffer
()
{
private
FlushingDataBuffer
()
{
this
.
buffer
=
new
DefaultDataBufferFactory
().
allocateBuffer
(
0
);
this
.
buffer
=
new
DefaultDataBufferFactory
().
allocateBuffer
(
0
);
}
}
public
FlushingDataBuffer
(
DataBuffer
buffer
)
{
Assert
.
notNull
(
buffer
);
this
.
buffer
=
buffer
;
}
@Override
@Override
public
DataBufferFactory
factory
()
{
public
DataBufferFactory
factory
()
{
...
...
spring-web-reactive/src/main/java/org/springframework/http/codec/SseEventEncoder.java
浏览文件 @
6b3d5f1b
...
@@ -115,7 +115,8 @@ public class SseEventEncoder extends AbstractEncoder<Object> {
...
@@ -115,7 +115,8 @@ public class SseEventEncoder extends AbstractEncoder<Object> {
return
Flux
.
concat
(
return
Flux
.
concat
(
encodeString
(
sb
.
toString
(),
bufferFactory
),
encodeString
(
sb
.
toString
(),
bufferFactory
),
dataBuffer
,
dataBuffer
,
encodeString
(
"\n"
,
bufferFactory
).
map
(
b
->
new
FlushingDataBuffer
(
b
))
encodeString
(
"\n"
,
bufferFactory
),
Mono
.
just
(
FlushingDataBuffer
.
INSTANCE
)
);
);
});
});
...
...
spring-web-reactive/src/test/java/org/springframework/core/codec/support/SseEventEncoderTests.java
浏览文件 @
6b3d5f1b
...
@@ -18,6 +18,7 @@ package org.springframework.core.codec.support;
...
@@ -18,6 +18,7 @@ package org.springframework.core.codec.support;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Test
;
import
org.junit.Test
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
...
@@ -26,14 +27,11 @@ import reactor.core.test.TestSubscriber;
...
@@ -26,14 +27,11 @@ import reactor.core.test.TestSubscriber;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase
;
import
org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase
;
import
org.springframework.core.io.buffer.DataBuffer
;
import
org.springframework.core.io.buffer.DataBuffer
;
import
org.springframework.core.io.buffer.FlushingDataBuffer
;
import
org.springframework.http.codec.SseEventEncoder
;
import
org.springframework.http.codec.SseEventEncoder
;
import
org.springframework.util.MimeType
;
import
org.springframework.util.MimeType
;
import
org.springframework.web.reactive.sse.SseEvent
;
import
org.springframework.web.reactive.sse.SseEvent
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
/**
* @author Sebastien Deleuze
* @author Sebastien Deleuze
*/
*/
...
@@ -77,7 +75,8 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
...
@@ -77,7 +75,8 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
"event:foo\n"
+
"event:foo\n"
+
"retry:123\n"
+
"retry:123\n"
+
":bla\n:bla bla\n:bla bla bla\n"
),
":bla\n:bla bla\n:bla bla bla\n"
),
stringConsumer
(
"\n"
)
stringConsumer
(
"\n"
),
b
->
assertEquals
(
FlushingDataBuffer
.
class
,
b
.
getClass
())
);
);
}
}
...
@@ -93,8 +92,10 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
...
@@ -93,8 +92,10 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
.
assertValuesWith
(
.
assertValuesWith
(
stringConsumer
(
"data:foo\n"
),
stringConsumer
(
"data:foo\n"
),
stringConsumer
(
"\n"
),
stringConsumer
(
"\n"
),
b
->
assertEquals
(
FlushingDataBuffer
.
class
,
b
.
getClass
()),
stringConsumer
(
"data:bar\n"
),
stringConsumer
(
"data:bar\n"
),
stringConsumer
(
"\n"
)
stringConsumer
(
"\n"
),
b
->
assertEquals
(
FlushingDataBuffer
.
class
,
b
.
getClass
())
);
);
}
}
...
@@ -110,12 +111,13 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
...
@@ -110,12 +111,13 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
.
assertValuesWith
(
.
assertValuesWith
(
stringConsumer
(
"data:foo\ndata:bar\n"
),
stringConsumer
(
"data:foo\ndata:bar\n"
),
stringConsumer
(
"\n"
),
stringConsumer
(
"\n"
),
b
->
assertEquals
(
FlushingDataBuffer
.
class
,
b
.
getClass
()),
stringConsumer
(
"data:foo\ndata:baz\n"
),
stringConsumer
(
"data:foo\ndata:baz\n"
),
stringConsumer
(
"\n"
)
stringConsumer
(
"\n"
),
b
->
assertEquals
(
FlushingDataBuffer
.
class
,
b
.
getClass
())
);
);
}
}
@Test
@Test
public
void
encodePojo
()
{
public
void
encodePojo
()
{
SseEventEncoder
encoder
=
new
SseEventEncoder
(
Arrays
.
asList
(
new
JacksonJsonEncoder
()));
SseEventEncoder
encoder
=
new
SseEventEncoder
(
Arrays
.
asList
(
new
JacksonJsonEncoder
()));
...
@@ -130,10 +132,12 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
...
@@ -130,10 +132,12 @@ public class SseEventEncoderTests extends AbstractDataBufferAllocatingTestCase {
stringConsumer
(
"{\"foo\":\"foofoo\",\"bar\":\"barbar\"}"
),
stringConsumer
(
"{\"foo\":\"foofoo\",\"bar\":\"barbar\"}"
),
stringConsumer
(
"\n"
),
stringConsumer
(
"\n"
),
stringConsumer
(
"\n"
),
stringConsumer
(
"\n"
),
b
->
assertEquals
(
FlushingDataBuffer
.
class
,
b
.
getClass
()),
stringConsumer
(
"data:"
),
stringConsumer
(
"data:"
),
stringConsumer
(
"{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}"
),
stringConsumer
(
"{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}"
),
stringConsumer
(
"\n"
),
stringConsumer
(
"\n"
),
stringConsumer
(
"\n"
)
stringConsumer
(
"\n"
),
b
->
assertEquals
(
FlushingDataBuffer
.
class
,
b
.
getClass
())
);
);
}
}
...
...
spring-web-reactive/src/test/java/org/springframework/http/server/reactive/FlushingIntegrationTests.java
浏览文件 @
6b3d5f1b
...
@@ -70,14 +70,15 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
...
@@ -70,14 +70,15 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
public
Mono
<
Void
>
handle
(
ServerHttpRequest
request
,
ServerHttpResponse
response
)
{
public
Mono
<
Void
>
handle
(
ServerHttpRequest
request
,
ServerHttpResponse
response
)
{
Flux
<
DataBuffer
>
responseBody
=
Flux
Flux
<
DataBuffer
>
responseBody
=
Flux
.
interval
(
50
)
.
interval
(
50
)
.
take
(
2
)
.
concatWith
(
Flux
.
never
())
.
map
(
l
->
{
.
map
(
l
->
{
byte
[]
data
=
(
"data"
+
l
).
getBytes
();
byte
[]
data
=
(
"data"
+
l
).
getBytes
();
DataBuffer
buffer
=
response
.
bufferFactory
().
allocateBuffer
(
data
.
length
);
DataBuffer
buffer
=
response
.
bufferFactory
().
allocateBuffer
(
data
.
length
);
buffer
.
write
(
data
);
buffer
.
write
(
data
);
return
new
FlushingDataBuffer
(
buffer
);
return
buffer
;
});
})
.
take
(
2
)
.
concatWith
(
Mono
.
just
(
FlushingDataBuffer
.
INSTANCE
))
.
concatWith
(
Flux
.
never
());
return
response
.
writeWith
(
responseBody
);
return
response
.
writeWith
(
responseBody
);
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录