Fixed checkStyle and ErrorProne warns

This commit is contained in:
andsel
2018-04-26 22:23:06 +02:00
parent 1a6dd8a259
commit 033a428184
81 changed files with 680 additions and 424 deletions
@@ -19,6 +19,8 @@ package io.moquette.server.config;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -51,7 +53,7 @@ public class ClasspathResourceLoader implements IResourceLoader {
public Reader loadResource(String relativePath) {
LOG.info("Loading resource. RelativePath = {}.", relativePath);
InputStream is = this.classLoader.getResourceAsStream(relativePath);
return is != null ? new InputStreamReader(is) : null;
return is != null ? new InputStreamReader(is, StandardCharsets.UTF_8) : null;
}
@Override
@@ -24,6 +24,8 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.ParseException;
import java.util.Properties;
@@ -55,15 +57,10 @@ class ConfigurationParser {
return;
}
try {
FileReader reader = new FileReader(file);
Reader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8);
parse(reader);
} catch (FileNotFoundException fex) {
LOG.warn(
String.format(
"parsing not existing file %s, so fallback on default configuration!",
file.getAbsolutePath()),
fex);
return;
} catch (IOException fex) {
LOG.warn("parsing not existing file {}, fallback on default configuration!", file.getAbsolutePath(), fex);
}
}
@@ -19,10 +19,15 @@ package io.moquette.server.config;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.nio.charset.StandardCharsets.UTF_8;
public class FileResourceLoader implements IResourceLoader {
private static final Logger LOG = LoggerFactory.getLogger(FileResourceLoader.class);
@@ -68,8 +73,8 @@ public class FileResourceLoader implements IResourceLoader {
throw new ResourceIsDirectoryException("File \"" + f + "\" is a directory!");
}
try {
return new FileReader(f);
} catch (FileNotFoundException e) {
return Files.newBufferedReader(f.toPath(), UTF_8);
} catch (IOException e) {
LOG.error("The file does not exist. Path = {}.", f.getAbsolutePath());
return null;
}