< prev index next >
core/org.openjdk.jmc.agent/src/test/java/org/openjdk/jmc/agent/test/util/TestToolkit.java
Print this page
*** 46,60 ****
public final class TestToolkit {
public static final Random RND = new Random();
private TestToolkit() {
! throw new UnsupportedOperationException("Not to be instantiated."); //$NON-NLS-1$
}
public static byte[] getByteCode(Class<?> c) throws IOException {
! InputStream is = c.getClassLoader().getResourceAsStream(c.getName().replace('.', '/') + ".class"); //$NON-NLS-1$
return readFully(is, -1, true);
}
public static byte[] readFully(InputStream is, int length, boolean readAll) throws IOException {
byte[] output = {};
--- 46,60 ----
public final class TestToolkit {
public static final Random RND = new Random();
private TestToolkit() {
! throw new UnsupportedOperationException("Not to be instantiated.");
}
public static byte[] getByteCode(Class<?> c) throws IOException {
! InputStream is = c.getClassLoader().getResourceAsStream(c.getName().replace('.', '/') + ".class");
return readFully(is, -1, true);
}
public static byte[] readFully(InputStream is, int length, boolean readAll) throws IOException {
byte[] output = {};
*** 73,83 ****
bytesToRead = output.length - pos;
}
int cc = is.read(output, pos, bytesToRead);
if (cc < 0) {
if (readAll && length != Integer.MAX_VALUE) {
! throw new EOFException("Detect premature EOF"); //$NON-NLS-1$
} else {
if (output.length != pos) {
output = Arrays.copyOf(output, pos);
}
break;
--- 73,83 ----
bytesToRead = output.length - pos;
}
int cc = is.read(output, pos, bytesToRead);
if (cc < 0) {
if (readAll && length != Integer.MAX_VALUE) {
! throw new EOFException("Detect premature EOF");
} else {
if (output.length != pos) {
output = Arrays.copyOf(output, pos);
}
break;
*** 101,121 ****
}
public static InputStream getProbesXML(String testName) {
try {
String s = readTemplate();
! s = s.replaceAll("%TEST_NAME%", testName); //$NON-NLS-1$
return new ByteArrayInputStream(s.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static String readTemplate() throws IOException {
! InputStream inputStream = InstrumentMe.class.getResourceAsStream("jfrprobes_template.xml"); //$NON-NLS-1$
String s = readString(inputStream);
closeSilently(inputStream);
return s;
}
--- 101,121 ----
}
public static InputStream getProbesXML(String testName) {
try {
String s = readTemplate();
! s = s.replaceAll("%TEST_NAME%", testName);
return new ByteArrayInputStream(s.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static String readTemplate() throws IOException {
! InputStream inputStream = InstrumentMe.class.getResourceAsStream("jfrprobes_template.xml");
String s = readString(inputStream);
closeSilently(inputStream);
return s;
}
*** 130,140 ****
private static String readString(BufferedReader reader) throws IOException {
String s;
StringBuilder builder = new StringBuilder();
try {
while ((s = reader.readLine()) != null) {
! builder.append(s + "\r"); //$NON-NLS-1$
}
s = builder.toString();
} finally {
closeSilently(reader);
}
--- 130,140 ----
private static String readString(BufferedReader reader) throws IOException {
String s;
StringBuilder builder = new StringBuilder();
try {
while ((s = reader.readLine()) != null) {
! builder.append(s + "\r");
}
s = builder.toString();
} finally {
closeSilently(reader);
}
< prev index next >