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
| package com.peofofo.model;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JOptionPane;
public class LicenceSerializer {
private int licence;
public LicenceSerializer(){
try {
File file = new File("file/sack.lic");
if(file.length() > 0)
{
ObjectInputStream ois = new ObjectInputStream(
new BufferedInputStream(
new FileInputStream(
file)));
Valide_licence listelicence = (Valide_licence)ois.readObject();
ois.close();
listelicence.toString();
licence= listelicence.licenceGet();
System.out.println("Lecture "+listelicence.toString());
JOptionPane.showMessageDialog(null, "Lecture - Fichier fichier sack trouvé !\n Lecture "+listelicence.toString()+"\n", "OK", JOptionPane.ERROR_MESSAGE);
}
else{
System.out.println("Le logiciel n'est pas enregistré");
}
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Lecture - Fichier pas trouvé depuis le chargement du fichier sack !\n" + e.getCause()+"\n", "ERREUR", JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Lecture - IO Exeption depuis le chargement du fichier sack !\n" + e.getCause()+"\n", "ERREUR", JOptionPane.ERROR_MESSAGE);
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, "Lecture - ClassNotFound depuis le chargement depuis le fichier sack !\n" + e.getCause()+"\n", "ERREUR", JOptionPane.ERROR_MESSAGE);
}
}
public void serialize(Valide_licence listelicence){
System.out.println("Ecriture : " + listelicence.toString());
try {
ObjectOutputStream oos = new ObjectOutputStream(
new BufferedOutputStream(
new FileOutputStream(
new File("file/sack.lic"))));
oos.writeObject(listelicence);
oos.close();
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Ecriture - Fichier pas trouvé depuis le chargement du fichier sack !\n !", "ERREUR", JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Ecriture - IO Exeption depuis le chargement du fichier sack !\n", "ERREUR", JOptionPane.ERROR_MESSAGE);
}
}
public int getLicence(){
return this.licence;
}
} |
Partager