Skip to content

Commit 45126bf

Browse files
committed
minor addition to BaseTest
1 parent 685f44e commit 45126bf

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/test/java/com/fasterxml/jackson/core/BaseTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,4 +624,27 @@ protected int[] calcQuads(byte[] wordBytes) {
624624
}
625625
return result;
626626
}
627+
628+
protected byte[] readResource(String ref)
629+
{
630+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
631+
final byte[] buf = new byte[4000];
632+
633+
InputStream in = getClass().getResourceAsStream(ref);
634+
if (in != null) {
635+
try {
636+
int len;
637+
while ((len = in.read(buf)) > 0) {
638+
bytes.write(buf, 0, len);
639+
}
640+
in.close();
641+
} catch (IOException e) {
642+
throw new RuntimeException("Failed to read resource '"+ref+"': "+e);
643+
}
644+
}
645+
if (bytes.size() == 0) {
646+
throw new IllegalArgumentException("Failed to read resource '"+ref+"': empty resource?");
647+
}
648+
return bytes.toByteArray();
649+
}
627650
}

0 commit comments

Comments
 (0)