@Override public synchronized byte[] getBytes() throws Exception { if (data != null) { return data; } InputStream in = SystemUtils.getResource(resource); if (in == null) { throw new Exception("RESOURCE '" + resource + "' NOT FOUND."); } ByteArrayOutputStream out = new ByteArrayOutputStream(); // you can configure the buffer size byte[] buffer = new byte[1024]; while (in.read(buffer) != -1) { out.write(buffer); } data = out.toByteArray(); return data; }