Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove commons io #322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}