mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Cleanup class JsonSerializer
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user