Cleanup class JsonSerializer

This commit is contained in:
Per Minborg
2020-12-14 15:36:29 +01:00
parent d38066c3f6
commit 932923bf83
@@ -51,7 +51,9 @@ final class JsonSerializer {
"</dependency>\n";
private static final Logger LOG = LoggerFactory.getLogger(JsonSerializer.class);
static synchronized <K, V> void getAll(File toFile, Map<K, V> map, List<?> jsonConverters) throws IOException {
static synchronized <K, V> void getAll(final File toFile,
final Map<K, V> map,
final List<?> jsonConverters) throws IOException {
final XStream xstream = xStream(map, jsonConverters);
try (OutputStream outputStream = createOutputStream(toFile)) {
@@ -59,7 +61,9 @@ final class JsonSerializer {
}
}
static synchronized <K, V> void putAll(File fromFile, Map<K, V> map, List<?> jsonConverters) throws IOException {
static synchronized <K, V> void putAll(final File fromFile,
final Map<K, V> map,
final List<?> jsonConverters) throws IOException {
final XStream xstream = xStream(map, jsonConverters);
try (InputStream inputStream = createInputStream(fromFile)) {
@@ -67,21 +71,21 @@ final class JsonSerializer {
}
}
private static InputStream createInputStream(File toFile) throws IOException {
private static InputStream createInputStream(final File toFile) throws IOException {
if (toFile.getName().toLowerCase().endsWith(".gz"))
return new GZIPInputStream(new FileInputStream(toFile));
else
return new FileInputStream(toFile);
}
private static OutputStream createOutputStream(File toFile) throws IOException {
private static OutputStream createOutputStream(final File toFile) throws IOException {
if (toFile.getName().toLowerCase().endsWith(".gz"))
return new GZIPOutputStream(new FileOutputStream(toFile));
else
return new FileOutputStream(toFile);
}
private static <K, V> XStream xStream(Map<K, V> map, List<?> jsonConverters) {
private static <K, V> XStream xStream(final Map<K, V> map, final List<?> jsonConverters) {
try {
final XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.setMode(XStream.NO_REFERENCES);
@@ -109,7 +113,7 @@ final class JsonSerializer {
}
}
private static <K, V> void registerChronicleMapConverter(Map<K, V> map, XStream xstream) {
private static <K, V> void registerChronicleMapConverter(final Map<K, V> map, final XStream xstream) {
xstream.registerConverter(new VanillaChronicleMapConverter<>(map));
}
}