99import java .util .HashMap ;
1010import java .util .Map ;
1111
12+ /**
13+ *
14+ * RainbowFishSerializer provides methods for reading and writing RainbowFish objects to file.
15+ * Tolerant Reader pattern is implemented here by serializing maps instead of RainbowFish objects.
16+ * This way the reader does not break even though new properties are added to the schema.
17+ *
18+ */
1219public class RainbowFishSerializer {
1320
21+ /**
22+ * Write V1 RainbowFish to file
23+ * @param rainbowFish
24+ * @param filename
25+ * @throws IOException
26+ */
1427 public static void writeV1 (RainbowFish rainbowFish , String filename ) throws IOException {
1528 Map <String , String > map = new HashMap <>();
1629 map .put ("name" , rainbowFish .getName ());
@@ -24,6 +37,12 @@ public static void writeV1(RainbowFish rainbowFish, String filename) throws IOEx
2437 fileOut .close ();
2538 }
2639
40+ /**
41+ * Write V2 RainbowFish to file
42+ * @param rainbowFish
43+ * @param filename
44+ * @throws IOException
45+ */
2746 public static void writeV2 (RainbowFishV2 rainbowFish , String filename ) throws IOException {
2847 Map <String , String > map = new HashMap <>();
2948 map .put ("name" , rainbowFish .getName ());
@@ -40,6 +59,13 @@ public static void writeV2(RainbowFishV2 rainbowFish, String filename) throws IO
4059 fileOut .close ();
4160 }
4261
62+ /**
63+ * Read V1 RainbowFish from file
64+ * @param filename
65+ * @return
66+ * @throws IOException
67+ * @throws ClassNotFoundException
68+ */
4369 public static RainbowFish readV1 (String filename ) throws IOException , ClassNotFoundException {
4470 Map <String , String > map = null ;
4571 FileInputStream fileIn = new FileInputStream (filename );
0 commit comments