Created
March 31, 2011 15:08
-
-
Save realbot/896529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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