Here you can find the source of getBytes(Class> clazz)
public static byte[] getBytes(Class<?> clazz) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] getBytes(Class<?> clazz) throws IOException { String resourcePath = clazz.getName().replace('.', '/') + ".class"; // System.out.println("Util.getBytes():" + resourcePath); ClassLoader loader = clazz.getClassLoader(); InputStream in;//from ww w . ja v a 2s. c om if (loader == null) { in = ClassLoader.getSystemResourceAsStream(resourcePath); } else { in = loader.getResourceAsStream(resourcePath); } ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[100]; while (true) { int len = in.read(buf); if (len < 0) { break; } out.write(buf, 0, len); } in.close(); return out.toByteArray(); } }