Skip to content

Commit

Permalink
fix for file not found execption at the graphite extension module
Browse files Browse the repository at this point in the history
  • Loading branch information
Slim Bouguerra committed May 4, 2016
1 parent 841be5c commit 805d5dc
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.metamx.common.ISE;
import com.metamx.common.logger.Logger;
import com.metamx.emitter.service.ServiceMetricEvent;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -247,13 +249,16 @@ private ImmutableSortedMap<String, ImmutableSet<String>> readMap(final String ma
{
String fileContent;
String actualPath = mapPath;
if (Strings.isNullOrEmpty(mapPath)) {
actualPath = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json").getFile();
LOGGER.warn("using default whiteList map located at [%s]", actualPath);
}

try {
fileContent = Files.asCharSource(new File(actualPath), Charset.forName("UTF-8")).read();
if (Strings.isNullOrEmpty(mapPath)) {
actualPath = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json").getFile();
LOGGER.info("using default whiteList map located at [%s]", actualPath);
fileContent = CharStreams.toString(new InputStreamReader(this.getClass()
.getClassLoader()
.getResourceAsStream("defaultWhiteListMap.json")));
} else {
fileContent = Files.asCharSource(new File(mapPath), Charset.forName("UTF-8")).read();
}
return mapper.reader(new TypeReference<ImmutableSortedMap<String, ImmutableSet<String>>>()
{
}).readValue(fileContent);
Expand Down

0 comments on commit 805d5dc

Please sign in to comment.