|
| 1 | +import java.io.FileOutputStream; |
| 2 | +import java.io.ObjectOutputStream; |
| 3 | +import java.io.Serializable; |
| 4 | +import java.util.ArrayList; |
| 5 | +import java.util.Collection; |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.LinkedList; |
| 8 | +import java.util.Map; |
| 9 | +import java.util.Queue; |
| 10 | +import java.util.concurrent.ConcurrentLinkedQueue; |
| 11 | + |
| 12 | +import org.junit.Test; |
| 13 | + |
| 14 | +class CollectionsSerializableBean implements Serializable { |
| 15 | + // Collections |
| 16 | + public Collection<String> arrayList; |
| 17 | + public Collection<String> linkedList; |
| 18 | + public Map<String, Object> hashMap; |
| 19 | + public Queue<String> queue; |
| 20 | + |
| 21 | + public CollectionsSerializableBean() |
| 22 | + { |
| 23 | + super(); |
| 24 | + |
| 25 | + arrayList = new ArrayList<String>(); |
| 26 | + arrayList.add("e1"); |
| 27 | + arrayList.add("e2"); |
| 28 | + |
| 29 | + linkedList = new LinkedList<String>(); |
| 30 | + linkedList.add("ll1"); |
| 31 | + linkedList.add("ll2"); |
| 32 | + |
| 33 | + hashMap = new HashMap<String, Object>(); |
| 34 | + hashMap.put("k1", null); |
| 35 | + hashMap.put("k2", "value2"); |
| 36 | + hashMap.put("k3", arrayList); |
| 37 | + hashMap.put("k3", linkedList); |
| 38 | + |
| 39 | + queue = new ConcurrentLinkedQueue<String>(); |
| 40 | + queue.add("q1"); |
| 41 | + queue.add("q2"); |
| 42 | + queue.add("q3"); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +public class CollectionsTest { |
| 47 | + |
| 48 | + ObjectOutputStream oos; |
| 49 | + FileOutputStream fos; |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testCollections() throws Exception { |
| 53 | + oos = new ObjectOutputStream(fos = new FileOutputStream("objCollections.ser")); |
| 54 | + oos.writeObject(new CollectionsSerializableBean()); |
| 55 | + oos.flush(); |
| 56 | + } |
| 57 | +} |
0 commit comments