Use try with resources to read agent version
More compact and gets rid of warnings
This commit is contained in:
parent
023fb397b5
commit
7e1266b39f
|
@ -3,6 +3,7 @@ package datadog.trace.agent;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -11,6 +12,7 @@ import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
/** Entry point for initializing the agent. */
|
/** Entry point for initializing the agent. */
|
||||||
|
@ -317,26 +319,19 @@ public class TracingAgent {
|
||||||
*
|
*
|
||||||
* @return Agent version
|
* @return Agent version
|
||||||
*/
|
*/
|
||||||
public static String getAgentVersion() throws Exception {
|
public static String getAgentVersion() throws IOException {
|
||||||
BufferedReader output = null;
|
|
||||||
InputStreamReader input = null;
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
try {
|
try (final BufferedReader reader =
|
||||||
input =
|
new BufferedReader(
|
||||||
new InputStreamReader(
|
new InputStreamReader(
|
||||||
TracingAgent.class.getResourceAsStream("/dd-java-agent.version"), "UTF-8");
|
TracingAgent.class.getResourceAsStream("/dd-java-agent.version"),
|
||||||
output = new BufferedReader(input);
|
StandardCharsets.UTF_8))) {
|
||||||
for (int c = output.read(); c != -1; c = output.read()) {
|
|
||||||
|
for (int c = reader.read(); c != -1; c = reader.read()) {
|
||||||
sb.append((char) c);
|
sb.append((char) c);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
if (null != input) {
|
|
||||||
input.close();
|
|
||||||
}
|
|
||||||
if (null != output) {
|
|
||||||
output.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString().trim();
|
return sb.toString().trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue