broker/ConfigurationParser: code formatter used
This commit is contained in:
@@ -13,11 +13,11 @@
|
|||||||
*
|
*
|
||||||
* You may elect to redistribute this code under either of these licenses.
|
* You may elect to redistribute this code under either of these licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.moquette.server.config;
|
package io.moquette.server.config;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -30,8 +30,8 @@ import java.util.Properties;
|
|||||||
/**
|
/**
|
||||||
* Mosquitto configuration parser.
|
* Mosquitto configuration parser.
|
||||||
*
|
*
|
||||||
* A line that at the very first has # is a comment
|
* A line that at the very first has # is a comment Each line has key value format, where the
|
||||||
* Each line has key value format, where the separator used it the space.
|
* separator used it the space.
|
||||||
*
|
*
|
||||||
* @author andrea
|
* @author andrea
|
||||||
*/
|
*/
|
||||||
@@ -50,14 +50,21 @@ class ConfigurationParser {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
LOG.warn(String.format("parsing not existing file %s, so fallback on default configuration!", file.getAbsolutePath()));
|
LOG.warn(
|
||||||
|
String.format(
|
||||||
|
"parsing not existing file %s, so fallback on default configuration!",
|
||||||
|
file.getAbsolutePath()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
FileReader reader = new FileReader(file);
|
FileReader reader = new FileReader(file);
|
||||||
parse(reader);
|
parse(reader);
|
||||||
} catch (FileNotFoundException fex) {
|
} catch (FileNotFoundException fex) {
|
||||||
LOG.warn(String.format("parsing not existing file %s, so fallback on default configuration!", file.getAbsolutePath()), fex);
|
LOG.warn(
|
||||||
|
String.format(
|
||||||
|
"parsing not existing file %s, so fallback on default configuration!",
|
||||||
|
file.getAbsolutePath()),
|
||||||
|
fex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,11 +72,12 @@ class ConfigurationParser {
|
|||||||
/**
|
/**
|
||||||
* Parse the configuration
|
* Parse the configuration
|
||||||
*
|
*
|
||||||
* @throws ParseException if the format is not compliant.
|
* @throws ParseException
|
||||||
|
* if the format is not compliant.
|
||||||
*/
|
*/
|
||||||
void parse(Reader reader) throws ParseException {
|
void parse(Reader reader) throws ParseException {
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
//just log and return default properties
|
// just log and return default properties
|
||||||
LOG.warn("parsing NULL reader, so fallback on default configuration!");
|
LOG.warn("parsing NULL reader, so fallback on default configuration!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -81,19 +89,19 @@ class ConfigurationParser {
|
|||||||
int commentMarker = line.indexOf('#');
|
int commentMarker = line.indexOf('#');
|
||||||
if (commentMarker != -1) {
|
if (commentMarker != -1) {
|
||||||
if (commentMarker == 0) {
|
if (commentMarker == 0) {
|
||||||
//skip its a comment
|
// skip its a comment
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
//it's a malformed comment
|
// it's a malformed comment
|
||||||
throw new ParseException(line, commentMarker);
|
throw new ParseException(line, commentMarker);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (line.isEmpty() || line.matches("^\\s*$")) {
|
if (line.isEmpty() || line.matches("^\\s*$")) {
|
||||||
//skip it's a black line
|
// skip it's a black line
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//split till the first space
|
// split till the first space
|
||||||
int delimiterIdx = line.indexOf(' ');
|
int delimiterIdx = line.indexOf(' ');
|
||||||
String key = line.substring(0, delimiterIdx).trim();
|
String key = line.substring(0, delimiterIdx).trim();
|
||||||
String value = line.substring(delimiterIdx).trim();
|
String value = line.substring(delimiterIdx).trim();
|
||||||
@@ -103,12 +111,10 @@ class ConfigurationParser {
|
|||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new ParseException("Failed to read", 1);
|
throw new ParseException("Failed to read", 1);
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user