public static int writeStreamTo( final InputStream input, final OutputStream output, int bufferSize) throws IOException { int available = Math.min(input.available(), 256 * KB); byte[] buffer = new byte[Math.max(bufferSize, available)]; int answer = 0; int count = input.read(buffer); while (count >= 0) { output.write(buffer, 0, count); answer += count; count = input.read(buffer); } return answer; }
public byte[] getBytes(String className) { try { Tracer.mark(); String realName = className.replace(".", "/"); realName += ".class"; JarEntry je = jf.getJarEntry(realName); InputStream is = jf.getInputStream(je); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buff = new byte[4096]; while (is.available() > 0) { int read = is.read(buff); baos.write(buff, 0, read); } is.close(); return baos.toByteArray(); } catch (Exception e) { } finally { Tracer.unmark(); } return null; }