minor addition to BaseTest
@@ -624,4 +624,27 @@ public abstract class BaseTest
}
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();
+ }
}
