Skip to content

Instantly share code, notes, and snippets.

@dblevins
Created June 10, 2009 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dblevins/127606 to your computer and use it in GitHub Desktop.
Save dblevins/127606 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.net.URL;
/**
* @version $Revision$ $Date$
*/
public class Utils {
public static byte[] getBytes(String name) throws IOException {
URL url = Utils.class.getClassLoader().getResource(name);
InputStream in = url.openStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = in.read();
while (i != -1) {
baos.write(i);
i = in.read();
}
byte[] bytes = baos.toByteArray();
return bytes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment