3 Commits

Author SHA1 Message Date
  Jesus 41255f824f Merge remote-tracking branch 'origin/main' 2 years ago
  Jesus 344930ab15 moving files 2 years ago
  Jesus d865d218a2 act2 2 years ago
7 changed files with 31 additions and 46 deletions
Split View
  1. +9
    -10
      src/main/java/com/jesuspinar/miobjeto/Main.java
  2. +2
    -3
      src/main/java/com/jesuspinar/miobjeto/controller/DataTbl.java
  3. +1
    -3
      src/main/java/com/jesuspinar/miobjeto/controller/ObjReader.java
  4. +17
    -0
      src/main/java/com/jesuspinar/miobjeto/controller/ObjWriter.java
  5. +1
    -1
      src/main/java/com/jesuspinar/miobjeto/model/People.java
  6. +1
    -1
      src/main/java/com/jesuspinar/miobjeto/model/Person.java
  7. +0
    -28
      src/main/java/com/jesuspinar/miobjeto/serializable/controller/ObjWriter.java

src/main/java/com/jesuspinar/miobjeto/serializable/Main.java → src/main/java/com/jesuspinar/miobjeto/Main.java View File

@ -1,9 +1,9 @@
package com.jesuspinar.miobjeto.serializable;
package com.jesuspinar.miobjeto;
import com.jesuspinar.miobjeto.serializable.controller.ObjReader;
import com.jesuspinar.miobjeto.serializable.controller.ObjWriter;
import com.jesuspinar.miobjeto.serializable.model.Person;
import com.jesuspinar.miobjeto.serializable.model.People;
import com.jesuspinar.miobjeto.controller.ObjReader;
import com.jesuspinar.miobjeto.controller.ObjWriter;
import com.jesuspinar.miobjeto.model.Person;
import com.jesuspinar.miobjeto.model.People;
import java.io.File;
@ -22,13 +22,12 @@ public class Main {
boolean isWritten = ObjWriter.write(data,file);
//Test serialization
People dat = null;
People p = null;
if (isWritten) {
dat = (People) ObjReader.read(file);
}
if (dat != null){
System.out.println(dat.toString());
p = (People) ObjReader.read(file);
System.out.println(p.toString());
}
}
}

+ 2
- 3
src/main/java/com/jesuspinar/miobjeto/controller/DataTbl.java View File

@ -1,9 +1,8 @@
package com.jesuspinar.miobjeto.controller;
import com.jesuspinar.miobjeto.model.PersonE;
import com.jesuspinar.miobjeto.serializable.controller.ObjReader;
import com.jesuspinar.miobjeto.serializable.model.People;
import com.jesuspinar.miobjeto.serializable.model.Person;
import com.jesuspinar.miobjeto.model.People;
import com.jesuspinar.miobjeto.model.Person;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;


src/main/java/com/jesuspinar/miobjeto/serializable/controller/ObjReader.java → src/main/java/com/jesuspinar/miobjeto/controller/ObjReader.java View File

@ -1,6 +1,4 @@
package com.jesuspinar.miobjeto.serializable.controller;
import com.jesuspinar.miobjeto.serializable.model.Person;
package com.jesuspinar.miobjeto.controller;
import java.io.*;

+ 17
- 0
src/main/java/com/jesuspinar/miobjeto/controller/ObjWriter.java View File

@ -0,0 +1,17 @@
package com.jesuspinar.miobjeto.controller;
import java.io.*;
public class ObjWriter {
public static boolean write(Object obj, File out) {
try (FileOutputStream fos = new FileOutputStream(out);
ObjectOutputStream oos = new ObjectOutputStream(fos)
){
oos.writeObject(obj);
oos.flush();
return true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

src/main/java/com/jesuspinar/miobjeto/serializable/model/People.java → src/main/java/com/jesuspinar/miobjeto/model/People.java View File

@ -1,4 +1,4 @@
package com.jesuspinar.miobjeto.serializable.model;
package com.jesuspinar.miobjeto.model;
import java.io.Serial;
import java.io.Serializable;

src/main/java/com/jesuspinar/miobjeto/serializable/model/Person.java → src/main/java/com/jesuspinar/miobjeto/model/Person.java View File

@ -1,4 +1,4 @@
package com.jesuspinar.miobjeto.serializable.model;
package com.jesuspinar.miobjeto.model;
import java.io.Serializable;

+ 0
- 28
src/main/java/com/jesuspinar/miobjeto/serializable/controller/ObjWriter.java View File

@ -1,28 +0,0 @@
package com.jesuspinar.miobjeto.serializable.controller;
import java.io.*;
public class ObjWriter {
public static boolean write(Object obj, File out) {
try (FileOutputStream fos = new FileOutputStream(out);
ObjectOutputStream oos = new ObjectOutputStream(fos)
){
oos.writeObject(obj);
oos.flush();
return true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static byte[] convertObjectToBytes(Object obj) {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
try (ObjectOutputStream objOutStream = new ObjectOutputStream(boas)
){
objOutStream.writeObject(obj);
return boas.toByteArray();
} catch (IOException ioe) {
ioe.printStackTrace();
}
throw new RuntimeException();
}
}

Loading…
Cancel
Save