Skip to content

Commit

Permalink
replace commons-io dependency (269KB) with JDK equivalents
Browse files Browse the repository at this point in the history
  • Loading branch information
richardstartin committed Sep 3, 2020
1 parent d7e2966 commit 2306f77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>com.datadoghq</groupId>
<artifactId>java-dogstatsd-client</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.beust.jcommander.ParameterException;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;

Expand Down Expand Up @@ -780,8 +779,8 @@ private boolean getJsonConfigs() {
log.debug("No configuration changes...");
return update;
}

InputStream jsonInputStream = IOUtils.toInputStream(response.getResponseBody(), UTF_8);
byte[] utf8 = response.getResponseBody().getBytes(UTF_8);
InputStream jsonInputStream = new ByteArrayInputStream(utf8);
JsonParser parser = new JsonParser(jsonInputStream);
int timestamp = ((Integer) parser.getJsonTimestamp()).intValue();
if (timestamp > lastJsonConfigTs) {
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/org/datadog/jmxfetch/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.fasterxml.jackson.jr.ob.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.yaml.snakeyaml.Yaml;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -147,7 +149,7 @@ public void flush() {
File statusFile = new File(this.statusFileLocation);
log.debug(
"Writing status to temp yaml file: " + statusFile.getAbsolutePath());
FileUtils.writeStringToFile(statusFile, yaml);
writeStringToFile(statusFile, yaml);
} catch (Exception e) {
log.warn("Cannot write status to temp file: " + e.getMessage());
}
Expand All @@ -164,4 +166,15 @@ public String getStatusFileLocation() {
public boolean isEnabled() {
return isEnabled;
}

private static void writeStringToFile(File file, String string) throws IOException {
FileOutputStream out = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(out);
try {
bos.write(string.getBytes(Charset.forName("UTF-8")));
} finally {
bos.close();
out.close();
}
}
}

0 comments on commit 2306f77

Please sign in to comment.