Resolves checkstyle errors for template-method thread-pool throttling tls tolerant-reader (#1073)
* Reduces checkstyle errors in template-method * Reduces checkstyle errors in thread-pool * Reduces checkstyle errors in throttling * Reduces checkstyle errors in tls * Reduces checkstyle errors in tolerant-reader
This commit is contained in:
committed by
Ilkka Seppälä
parent
9c8ad4485b
commit
b92eb5229d
@ -28,16 +28,13 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* RainbowFishSerializer provides methods for reading and writing {@link RainbowFish} objects to
|
||||
* file. Tolerant Reader pattern is implemented here by serializing maps instead of
|
||||
* {@link RainbowFish} objects. This way the reader does not break even though new properties are
|
||||
* added to the schema.
|
||||
*
|
||||
* file. Tolerant Reader pattern is implemented here by serializing maps instead of {@link
|
||||
* RainbowFish} objects. This way the reader does not break even though new properties are added to
|
||||
* the schema.
|
||||
*/
|
||||
public final class RainbowFishSerializer {
|
||||
|
||||
@ -45,54 +42,55 @@ public final class RainbowFishSerializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Write V1 RainbowFish to file
|
||||
* Write V1 RainbowFish to file.
|
||||
*/
|
||||
public static void writeV1(RainbowFish rainbowFish, String filename) throws IOException {
|
||||
var map = Map.of(
|
||||
"name", rainbowFish.getName(),
|
||||
"age", String.format("%d", rainbowFish.getAge()),
|
||||
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
|
||||
"weightTons", String.format("%d", rainbowFish.getWeightTons())
|
||||
"name", rainbowFish.getName(),
|
||||
"age", String.format("%d", rainbowFish.getAge()),
|
||||
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
|
||||
"weightTons", String.format("%d", rainbowFish.getWeightTons())
|
||||
);
|
||||
|
||||
try (var fileOut = new FileOutputStream(filename);
|
||||
var objOut = new ObjectOutputStream(fileOut)) {
|
||||
var objOut = new ObjectOutputStream(fileOut)) {
|
||||
objOut.writeObject(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write V2 RainbowFish to file
|
||||
* Write V2 RainbowFish to file.
|
||||
*/
|
||||
public static void writeV2(RainbowFishV2 rainbowFish, String filename) throws IOException {
|
||||
var map = Map.of(
|
||||
"name", rainbowFish.getName(),
|
||||
"age", String.format("%d", rainbowFish.getAge()),
|
||||
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
|
||||
"weightTons", String.format("%d", rainbowFish.getWeightTons()),
|
||||
"angry", Boolean.toString(rainbowFish.getAngry()),
|
||||
"hungry", Boolean.toString(rainbowFish.getHungry()),
|
||||
"sleeping", Boolean.toString(rainbowFish.getSleeping())
|
||||
"name", rainbowFish.getName(),
|
||||
"age", String.format("%d", rainbowFish.getAge()),
|
||||
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
|
||||
"weightTons", String.format("%d", rainbowFish.getWeightTons()),
|
||||
"angry", Boolean.toString(rainbowFish.getAngry()),
|
||||
"hungry", Boolean.toString(rainbowFish.getHungry()),
|
||||
"sleeping", Boolean.toString(rainbowFish.getSleeping())
|
||||
);
|
||||
|
||||
try (var fileOut = new FileOutputStream(filename);
|
||||
var objOut = new ObjectOutputStream(fileOut)) {
|
||||
var objOut = new ObjectOutputStream(fileOut)) {
|
||||
objOut.writeObject(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read V1 RainbowFish from file
|
||||
* Read V1 RainbowFish from file.
|
||||
*/
|
||||
public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException {
|
||||
Map<String, String> map = null;
|
||||
|
||||
try (var fileIn = new FileInputStream(filename);
|
||||
var objIn = new ObjectInputStream(fileIn)) {
|
||||
var objIn = new ObjectInputStream(fileIn)) {
|
||||
map = (Map<String, String>) objIn.readObject();
|
||||
}
|
||||
|
||||
return new RainbowFish(map.get("name"), Integer.parseInt(map.get("age")), Integer.parseInt(map.get("lengthMeters")),
|
||||
return new RainbowFish(map.get("name"), Integer.parseInt(map.get("age")), Integer
|
||||
.parseInt(map.get("lengthMeters")),
|
||||
Integer.parseInt(map.get("weightTons")));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user