try (InputStream in = clazz.getResourceAsStream(resource)) {
int read;
byte[] data = new byte[4096];
while ((read = in.read(data, 0, data.length)) != -1) {
if (read == data.length) {
buffer.appendBytes(data);
} else {
byte[] slice = new byte[read];
System.arraycopy(data, 0, slice, 0, slice.length);
buffer.appendBytes(slice);
}