@@ -4,50 +4,30 @@ public class Serialize
44{
55 public static void main (String [] args )
66 {
7+ String x = "www.jeremiahfaria.com" ;
8+
79 System .out .print ("\n " + "Serialize a String:" + "\n " );
8- Serialize .serialize ();
10+ Serialize .serialize (x );
911
1012 System .out .print ("\n " + "Deserialize a String:" + "\n " );
11- Serialize .deserialize ();
12- }
13- public static void serialize ()
14- {
15- String [] alpha = {"bravo" ,"charlie" ,"delta" };
16- try
17- {
18- ByteArrayOutputStream echo = new ByteArrayOutputStream ();
19- ObjectOutputStream foxtrot = new ObjectOutputStream (echo );
20- foxtrot .writeObject (alpha );
21- foxtrot .flush ();
22- System .out .print (echo .toString () + "\n \n " );
23- }
24- catch (Exception e )
25- {
26- System .out .print (e + "\n " );
27- }
13+ Serialize .deserialize (x );
14+
15+ System .out .print ("\n " );
2816 }
29- public static void deserialize ( )
17+ public static void serialize ( String data )
3018 {
31- String golf = "" ;
32- String [] alpha = {"bravo" ,"charlie" ,"delta" };
3319 try
3420 {
35- ByteArrayOutputStream echo = new ByteArrayOutputStream ();
36- ObjectOutputStream foxtrot = new ObjectOutputStream (echo );
37- foxtrot .writeObject (alpha );
38- foxtrot .flush ();
39- golf = echo .toString ();
40-
41- byte [] b = golf .getBytes ();
42- ByteArrayInputStream bi = new ByteArrayInputStream (b );
43- ObjectInputStream si = new ObjectInputStream (bi );
44- //MyObject obj = (MyObject) si.readObject();
45-
46- System .out .print (si .readObject () + "\n \n " );
21+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
22+ ObjectOutputStream oos = new ObjectOutputStream (baos );
23+ oos .writeObject (data );
24+ oos .flush ();
25+ System .out .print (baos .toString () + "\n " );
4726 }
4827 catch (Exception e )
4928 {
5029 System .out .print (e + "\n " );
5130 }
5231 }
32+ public static void deserialize (String data ) {}
5333}
0 commit comments