Skip to content

Instantly share code, notes, and snippets.

@realbot
Created March 31, 2011 15:08
Show Gist options
  • Save realbot/896529 to your computer and use it in GitHub Desktop.
Save realbot/896529 to your computer and use it in GitHub Desktop.
byte[] obtainByteData(String filename) throws IOException {
InputStream inputStream = getClass().getResourceAsStream(filename);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
byte[] bytes = new byte[512];
int readBytes;
while ((readBytes = inputStream.read(bytes)) > 0) {
outputStream.write(bytes, 0, readBytes);
}
byte[] byteData = outputStream.toByteArray();
inputStream.close();
outputStream.close();
return byteData;
}
def obtainByteData(resource: filename): Array[Byte] = {
val is = getClass.getResourceAsStream(filename)
val byteData = continually(is.read).takeWhile(-1 !=).map(_.toByte).toArray
is.close()
byteData
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment