Skip to content

Commit

Permalink
minor addition to BaseTest
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 20, 2021
1 parent 685f44e commit 45126bf
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/java/com/fasterxml/jackson/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,27 @@ protected int[] calcQuads(byte[] wordBytes) {
}
return result;
}

protected byte[] readResource(String ref)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final byte[] buf = new byte[4000];

InputStream in = getClass().getResourceAsStream(ref);
if (in != null) {
try {
int len;
while ((len = in.read(buf)) > 0) {
bytes.write(buf, 0, len);
}
in.close();
} catch (IOException e) {
throw new RuntimeException("Failed to read resource '"+ref+"': "+e);
}
}
if (bytes.size() == 0) {
throw new IllegalArgumentException("Failed to read resource '"+ref+"': empty resource?");
}
return bytes.toByteArray();
}
}

0 comments on commit 45126bf

Please sign in to comment.