Finalizado soporte de persistencia
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
package Logica;
|
||||
|
||||
import java.io.EOFException;
|
||||
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 java.io.Serializable;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -66,9 +74,44 @@ private ArrayList<Mes> meses;
|
||||
return this.meses.get(this.mesActual).getTotal();
|
||||
}
|
||||
|
||||
public void guardarMeses(String nombre) throws IOException {
|
||||
FileOutputStream fichero = new FileOutputStream(nombre);
|
||||
ObjectOutputStream escritor = new ObjectOutputStream(fichero);
|
||||
for(Mes mes:this.meses) {
|
||||
for(Gestion gestion:mes.getGestiones()) {
|
||||
for(Transaccion transaccion:gestion.getElementos()) {
|
||||
escritor.writeObject(transaccion);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
escritor.close();
|
||||
fichero.close();
|
||||
}
|
||||
|
||||
public void cargarMeses(String nombre) throws IOException, ClassNotFoundException {
|
||||
FileInputStream fichero;
|
||||
try {
|
||||
fichero = new FileInputStream(nombre);
|
||||
}catch(FileNotFoundException e){
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectInputStream lector = new ObjectInputStream(fichero);
|
||||
try {
|
||||
while(true) {
|
||||
Transaccion transaccion = (Transaccion)lector.readObject();
|
||||
this.aniadirTransaccion(transaccion, transaccion.getGestion().getNombre(), transaccion.getGestion().esIngreso());
|
||||
}
|
||||
}catch(EOFException e) {
|
||||
lector.close();
|
||||
fichero.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Mes{
|
||||
class Mes implements Serializable{
|
||||
private int anio;
|
||||
private Month mes;
|
||||
ArrayList<Gestion> gestiones;
|
||||
|
||||
Reference in New Issue
Block a user