/** * Creates a instrumented version of the given class if possible. * * @param buffer definition of the class * @param name a name used for exception messages * @return instrumented definition * @throws IOException if the class can't be analyzed */ public byte[] instrument(final byte[] buffer, final String name) throws IOException { try { if (Java9Support.isPatchRequired(buffer)) { final byte[] result = instrument(new ClassReader(Java9Support.downgrade(buffer))); Java9Support.upgrade(result); return result; } else { return instrument(new ClassReader(buffer)); } } catch (final RuntimeException e) { throw instrumentError(name, e); } }
/** * Creates a instrumented version of the given class if possible. * * @param input stream to read class definition from * @param name a name used for exception messages * @return instrumented definition * @throws IOException if reading data from the stream fails or the class can't be instrumented */ public byte[] instrument(final InputStream input, final String name) throws IOException { try { return instrument(Java9Support.readFully(input), name); } catch (final RuntimeException e) { throw instrumentError(name, e); } }
/** * Creates a instrumented version of the given class file. * * @param input stream to read class definition from * @param output stream to write the instrumented version of the class to * @param name a name used for exception messages * @throws IOException if reading data from the stream fails or the class can't be instrumented */ public void instrument(final InputStream input, final OutputStream output, final String name) throws IOException { try { output.write(instrument(Java9Support.readFully(input), name)); } catch (final RuntimeException e) { throw instrumentError(name, e); } }