File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed
tolerant-reader/src/main/java/com/iluwatar Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .iluwatar ;
2
+
3
+ import java .io .Serializable ;
4
+
5
+ public class RainbowFish implements Serializable {
6
+
7
+ private static final long serialVersionUID = 1L ;
8
+
9
+ private String name ;
10
+ private int age ;
11
+ private int lengthMeters ;
12
+ private int weightTons ;
13
+
14
+ public String getName () {
15
+ return name ;
16
+ }
17
+ public void setName (String name ) {
18
+ this .name = name ;
19
+ }
20
+ public int getAge () {
21
+ return age ;
22
+ }
23
+ public void setAge (int age ) {
24
+ this .age = age ;
25
+ }
26
+ public int getLengthMeters () {
27
+ return lengthMeters ;
28
+ }
29
+ public void setLengthMeters (int lengthMeters ) {
30
+ this .lengthMeters = lengthMeters ;
31
+ }
32
+ public int getWeightTons () {
33
+ return weightTons ;
34
+ }
35
+ public void setWeightTons (int weightTons ) {
36
+ this .weightTons = weightTons ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ package com .iluwatar ;
2
+
3
+ import java .io .FileOutputStream ;
4
+ import java .io .IOException ;
5
+ import java .io .ObjectOutputStream ;
6
+ import java .util .HashMap ;
7
+ import java .util .Map ;
8
+
9
+ public class RainbowFishSerializer {
10
+
11
+ public void write (RainbowFish rainbowFish , String filename ) {
12
+ Map <String , String > map = new HashMap <>();
13
+ map .put ("name" , rainbowFish .getName ());
14
+ map .put ("age" , String .format ("%d" , rainbowFish .getAge ()));
15
+ map .put ("lengthMeters" , String .format ("%d" , rainbowFish .getLengthMeters ()));
16
+ map .put ("weightTons" , String .format ("%d" , rainbowFish .getWeightTons ()));
17
+ try {
18
+ FileOutputStream fileOut = new FileOutputStream ("fish.ser" );
19
+ ObjectOutputStream objOut = new ObjectOutputStream (fileOut );
20
+ objOut .writeObject (map );
21
+ objOut .close ();
22
+ fileOut .close ();
23
+ } catch (IOException e ) {
24
+ e .printStackTrace ();
25
+ }
26
+ }
27
+
28
+ // public RainbowFish read(String filename) {
29
+ // }
30
+ }
Original file line number Diff line number Diff line change
1
+ package com .iluwatar ;
2
+
3
+ public class RainbowFishV2 extends RainbowFish {
4
+
5
+ private boolean sleeping ;
6
+ private boolean hungry ;
7
+ private boolean angry ;
8
+
9
+ }
You can’t perform that action at this time.
0 commit comments