33
33
import java .util .HexFormat ;
34
34
import java .util .List ;
35
35
import java .util .Map ;
36
+ import java .util .stream .Collectors ;
36
37
import org .jruby .RubyString ;
37
38
import org .jruby .RubySymbol ;
38
39
import org .jruby .RubyTime ;
@@ -149,7 +150,7 @@ public void bigNumsBinaryRoundtrip() throws Exception {
149
150
150
151
@ Test
151
152
public void deserializeStringrefExtensionEnabled () throws Exception {
152
- byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-enabled.annotated-cbor.txt " );
153
+ byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-enabled.annotated-cbor.asc " );
153
154
Event event = Event .deserialize (stringrefCBOR );
154
155
event .getField ("[event][original]" );
155
156
assertEquals ("stringref" , event .getField ("test" ));
@@ -158,7 +159,7 @@ public void deserializeStringrefExtensionEnabled() throws Exception {
158
159
159
160
@ Test
160
161
public void deserializeStringrefExtensionDisabled () throws Exception {
161
- byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-disabled.annotated-cbor.txt " );
162
+ byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-disabled.annotated-cbor.asc " );
162
163
Event event = Event .deserialize (stringrefCBOR );
163
164
event .getField ("[event][original]" );
164
165
assertEquals ("stringref" , event .getField ("test" ));
@@ -627,9 +628,13 @@ static byte[] loadAnnotatedCBORFixture(String name) throws IOException {
627
628
try (InputStream resourceAsStream = EventTest .class .getResourceAsStream (name )) {
628
629
assertNotNull (resourceAsStream );
629
630
630
- String annotated = new String (resourceAsStream .readAllBytes (), StandardCharsets .UTF_8 );
631
- // annotated CBOR: strip #-initiated line comments, then strip whitespace to get hex
632
- String hexBytes = annotated .replaceAll ("#.*(\\ n|$)" , "" ).replaceAll ("\\ s" , "" );
631
+ final String annotatedFixture = new String (resourceAsStream .readAllBytes (), StandardCharsets .US_ASCII );
632
+ final String hexBytes = annotatedFixture .lines ()
633
+ // strip #-prefixed annotations
634
+ .map (line -> line .split ("#" , 2 )[0 ])
635
+ // strip all remaining whitespace
636
+ .map (line -> line .replaceAll ("\\ s" , "" ))
637
+ .collect (Collectors .joining ());
633
638
634
639
// result should be even number of hex digits
635
640
assert hexBytes .matches ("(?i:[0-9a-f]{2})*" );
0 commit comments