File tree Expand file tree Collapse file tree 3 files changed +20
-18
lines changed
main/java/org/springframework/data/redis/connection
test/java/org/springframework/data/redis/connection Expand file tree Collapse file tree 3 files changed +20
-18
lines changed Original file line number Diff line number Diff line change 16
16
package org .springframework .data .redis .connection ;
17
17
18
18
import org .springframework .data .redis .connection .util .ByteArrayWrapper ;
19
+ import org .springframework .data .redis .util .ByteUtils ;
19
20
import org .springframework .lang .Nullable ;
20
21
import org .springframework .util .Assert ;
21
22
import org .springframework .util .ObjectUtils ;
@@ -58,12 +59,12 @@ public boolean hasBody() {
58
59
return !ObjectUtils .isEmpty (body );
59
60
}
60
61
61
- public String getChannelAsString ( ) {
62
- return new String (channel );
62
+ public boolean channelStartsWith ( byte [] prefix ) {
63
+ return ByteUtils . startsWith (channel , prefix );
63
64
}
64
65
65
- public String getBodyAsString ( ) {
66
- return new String (body );
66
+ public boolean bodyStartsWith ( byte [] prefix ) {
67
+ return ByteUtils . startsWith (body , prefix );
67
68
}
68
69
69
70
public ByteArrayWrapper getChannelAsWrapper () {
Original file line number Diff line number Diff line change 18
18
import java .io .Serializable ;
19
19
20
20
import org .springframework .data .redis .connection .util .ByteArrayWrapper ;
21
+ import org .springframework .data .redis .util .ByteUtils ;
21
22
import org .springframework .util .ObjectUtils ;
22
23
23
24
/**
@@ -62,21 +63,21 @@ default boolean hasBody() {
62
63
}
63
64
64
65
/**
65
- * Returns the string representation of the channel associated with the message.
66
+ * Checks if the message channel starts with the given prefix
66
67
*
67
- * @return message channel as string. Never {@literal null}.
68
+ * @return {@code true} if the channel starts with the given prefix, otherwise {@code false}
68
69
*/
69
- default String getChannelAsString ( ) {
70
- return new String (getChannel ());
70
+ default boolean channelStartsWith ( byte [] prefix ) {
71
+ return ByteUtils . startsWith (getChannel (), prefix );
71
72
}
72
73
73
74
/**
74
- * Returns the string representation of the body (or the payload) of the message
75
+ * Checks if the message body starts with the given prefix
75
76
*
76
- * @return body as string. Never {@literal null}.
77
+ * @return {@code true} if the body starts with the given prefix, otherwise {@code false}
77
78
*/
78
- default String getBodyAsString ( ) {
79
- return new String (getBody ());
79
+ default boolean bodyStartsWith ( byte [] prefix ) {
80
+ return ByteUtils . startsWith (getBody (), prefix );
80
81
}
81
82
82
83
/**
Original file line number Diff line number Diff line change @@ -44,15 +44,15 @@ void testHasBody() {
44
44
}
45
45
46
46
@ Test
47
- void testGetChannelAsString () {
48
- assertThat (aMessageWithChannel (EMPTY_BYTES ).getChannelAsString ( )).isEmpty ();
49
- assertThat (aMessageWithChannel (CHANNEL_BYTES ).getChannelAsString ( )).isEqualTo ( CHANNEL );
47
+ void testChannelStartsWith () {
48
+ assertThat (aMessageWithChannel (EMPTY_BYTES ).channelStartsWith ( CHANNEL_BYTES )).isFalse ();
49
+ assertThat (aMessageWithChannel (CHANNEL_BYTES ).channelStartsWith ( CHANNEL_BYTES )).isTrue ( );
50
50
}
51
51
52
52
@ Test
53
- void testGetBodyAsString () {
54
- assertThat (aMessageWithBody (EMPTY_BYTES ).getBodyAsString ( )).isEmpty ();
55
- assertThat (aMessageWithBody (BODY_BYTES ).getBodyAsString ( )).isEqualTo ( BODY );
53
+ void testBodyStartsWith () {
54
+ assertThat (aMessageWithBody (EMPTY_BYTES ).bodyStartsWith ( BODY_BYTES )).isFalse ();
55
+ assertThat (aMessageWithBody (BODY_BYTES ).bodyStartsWith ( BODY_BYTES )).isTrue ( );
56
56
}
57
57
58
58
@ Test
You can’t perform that action at this time.
0 commit comments