Sérialisation des arrayList pour envoyé les fichiers via TCP
Bonjour,
j'ai quelques difficultés avec la sérialisation, voila le topo : Dans le cadre d'un projet on doit créer une pointeuse d'un côté et une appli principale qui gère tous les pointages d'un autre côté. Les deux IHM s'envoient des données via le protocole TCP et le système de sauvegarde de tous les employé et leurs pointages se fait par sérialisation. J'ai donc essayé de créer une classe "Serialisation" qui permetterai d'envoyer les fichier serialiser d'une IHM à une autre via TCP. J'ai montré la classe que j'ai écrite à l'enseignant en charge du projet et m'a mis un stop. J'ai donc essayé de comprendre mieux comment tout cela fonctionnait mais je n'y arrive pas. Pourriez vous me dire ce qu'il ne va pas dans ma classe ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
public class Serialisation implements Serializable{
private static ArrayList<Company> ListComp = new ArrayList<Company>();
private static ArrayList<Departement> ListDep = new ArrayList<Departement>();
private static ArrayList<Employee> ListEmp = new ArrayList<Employee>();
private static ArrayList<PlanningHebdo> ListPlanH = new ArrayList<PlanningHebdo>();
private static ArrayList<DayPlanning> ListDayPlan = new ArrayList<DayPlanning>();
private static ArrayList<Scoring> ListScoring = new ArrayList<Scoring>();
private File fichierCompany = new File("src/Company.ser");
private File fichierDepartement = new File("src/Departement.ser");
private File fichierEmployee = new File("src/Employee.ser");
private File fichierPlanningHebdo = new File("src/PlanningHebdo.ser");
private File fichierDayPlanning = new File("src/DayPlanning.ser");
private File fichierScoring = new File("src/Scoring.ser");
public void SerializeCompany(Company comp) {
ListComp.add(comp);
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichierCompany)) ;
oos.writeObject(ListComp);
oos.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
}
public void SerializeDepartement(Departement dep) {
ListDep.add(dep);
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichierDepartement)) ;
oos.writeObject(ListDep);
oos.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
}
public void SerializeEmployee(Employee emp) {
ListEmp.add(emp);
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichierEmployee)) ;
oos.writeObject(ListEmp);
oos.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
}
public void SerializePlanningH(PlanningHebdo PlanH) {
ListPlanH.add(PlanH);
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichierPlanningHebdo)) ;
oos.writeObject(ListPlanH);
oos.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
}
public void SerializeDayPlanning(DayPlanning dayP) {
ListDayPlan.add(dayP);
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichierDayPlanning)) ;
oos.writeObject(ListDayPlan);
oos.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
}
public void SerializeScoring(Scoring scor) {
ListScoring.add(scor);
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fichierScoring)) ;
oos.writeObject(ListScoring);
oos.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
}
public ArrayList<Company> DeserializeCompany() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fichierCompany)) ;
ListComp = (ArrayList<Company>) ois.readObject();
ois.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
return ListComp;
}
public ArrayList<Departement> DeserializeDepartement() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fichierDepartement)) ;
ListDep = (ArrayList<Departement>) ois.readObject();
ois.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
return ListDep;
}
public ArrayList<Employee> DeserializeEmployee() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fichierEmployee)) ;
ListEmp = (ArrayList<Employee>) ois.readObject();
ois.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
return ListEmp;
}
public ArrayList<PlanningHebdo> DeserializePlanningHebdo() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fichierPlanningHebdo)) ;
ListPlanH = (ArrayList<PlanningHebdo>) ois.readObject();
ois.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
return ListPlanH;
}
public ArrayList<DayPlanning> DeserializeDayPlanning() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fichierDayPlanning)) ;
ListDayPlan = (ArrayList<DayPlanning>) ois.readObject();
ois.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
return ListDayPlan;
}
public ArrayList<Scoring> DeserializeScoring() {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fichierScoring)) ;
ListScoring = (ArrayList<Scoring>) ois.readObject();
ois.close();
}
catch(IOException exc) {
exc.printStackTrace();
}
catch(ClassNotFoundException ex)
{
ex.printStackTrace();
}
return ListScoring;
}
} |