Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / remoteresource / SerializedClientController.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package oic.simulator.clientcontroller.remoteresource;
18
19 import java.io.FileInputStream;
20 import java.io.FileNotFoundException;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.ObjectInputStream;
24 import java.io.ObjectOutputStream;
25 import java.io.Serializable;
26 import java.util.List;
27
28 public class SerializedClientController implements Serializable {
29
30     public List<String> getResourceTypes() {
31         return m_resourceTypes;
32     }
33
34     public void setResourceTypes(List<String> resourceTypes) {
35         this.m_resourceTypes = resourceTypes;
36     }
37
38     public List<String> getFavorites() {
39         return m_favorites;
40     }
41
42     public void setFavorites(List<String> favorites) {
43         this.m_favorites = favorites;
44     }
45
46     public void serialize(String filePath) throws FileNotFoundException,
47             IOException {
48         FileOutputStream fileOut = null;
49         ObjectOutputStream out = null;
50         try {
51             fileOut = new FileOutputStream(filePath);
52             out = new ObjectOutputStream(fileOut);
53             out.writeObject(this);
54         } finally {
55             if (null != fileOut)
56                 fileOut.close();
57
58             if (null != out)
59                 out.close();
60         }
61     }
62
63     public static SerializedClientController deSerialize(String filePath)
64             throws FileNotFoundException, IOException, ClassNotFoundException {
65         FileInputStream fileIn = null;
66         ObjectInputStream in = null;
67         SerializedClientController r = null;
68         try {
69             fileIn = new FileInputStream(filePath);
70             in = new ObjectInputStream(fileIn);
71             r = (SerializedClientController) in.readObject();
72         } finally {
73             if (null != fileIn)
74                 fileIn.close();
75
76             if (null != in)
77                 in.close();
78         }
79
80         return r;
81     }
82
83     private List<String> m_resourceTypes;
84     private List<String> m_favorites;
85
86 }