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 1616package org .springframework .data .redis .connection ;
1717
1818import org .springframework .data .redis .connection .util .ByteArrayWrapper ;
19+ import org .springframework .data .redis .util .ByteUtils ;
1920import org .springframework .lang .Nullable ;
2021import org .springframework .util .Assert ;
2122import org .springframework .util .ObjectUtils ;
@@ -58,12 +59,12 @@ public boolean hasBody() {
5859 return !ObjectUtils .isEmpty (body );
5960 }
6061
61- public String getChannelAsString ( ) {
62- return new String (channel );
62+ public boolean channelStartsWith ( byte [] prefix ) {
63+ return ByteUtils . startsWith (channel , prefix );
6364 }
6465
65- public String getBodyAsString ( ) {
66- return new String (body );
66+ public boolean bodyStartsWith ( byte [] prefix ) {
67+ return ByteUtils . startsWith (body , prefix );
6768 }
6869
6970 public ByteArrayWrapper getChannelAsWrapper () {
Original file line number Diff line number Diff line change 1818import java .io .Serializable ;
1919
2020import org .springframework .data .redis .connection .util .ByteArrayWrapper ;
21+ import org .springframework .data .redis .util .ByteUtils ;
2122import org .springframework .util .ObjectUtils ;
2223
2324/**
@@ -62,21 +63,21 @@ default boolean hasBody() {
6263 }
6364
6465 /**
65- * Returns the string representation of the channel associated with the message.
66+ * Checks if the message channel starts with the given prefix
6667 *
67- * @return message channel as string. Never {@literal null}.
68+ * @return {@code true} if the channel starts with the given prefix, otherwise {@code false}
6869 */
69- default String getChannelAsString ( ) {
70- return new String (getChannel ());
70+ default boolean channelStartsWith ( byte [] prefix ) {
71+ return ByteUtils . startsWith (getChannel (), prefix );
7172 }
7273
7374 /**
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
7576 *
76- * @return body as string. Never {@literal null}.
77+ * @return {@code true} if the body starts with the given prefix, otherwise {@code false}
7778 */
78- default String getBodyAsString ( ) {
79- return new String (getBody ());
79+ default boolean bodyStartsWith ( byte [] prefix ) {
80+ return ByteUtils . startsWith (getBody (), prefix );
8081 }
8182
8283 /**
Original file line number Diff line number Diff line change @@ -44,15 +44,15 @@ void testHasBody() {
4444 }
4545
4646 @ 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 ( );
5050 }
5151
5252 @ 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 ( );
5656 }
5757
5858 @ Test
You can’t perform that action at this time.
0 commit comments