Browse Source

moving files

main
Jesus 2 years ago
parent
commit
344930ab15
8 changed files with 33 additions and 48 deletions
  1. +2
    -2
      src/main/java/com/jesuspinar/miobjeto/App.java
  2. +9
    -10
      src/main/java/com/jesuspinar/miobjeto/Main.java
  3. +2
    -3
      src/main/java/com/jesuspinar/miobjeto/controller/DataTbl.java
  4. +1
    -3
      src/main/java/com/jesuspinar/miobjeto/controller/ObjReader.java
  5. +17
    -0
      src/main/java/com/jesuspinar/miobjeto/controller/ObjWriter.java
  6. +1
    -1
      src/main/java/com/jesuspinar/miobjeto/model/People.java
  7. +1
    -1
      src/main/java/com/jesuspinar/miobjeto/model/Person.java
  8. +0
    -28
      src/main/java/com/jesuspinar/miobjeto/serializable/controller/ObjWriter.java

+ 2
- 2
src/main/java/com/jesuspinar/miobjeto/App.java View File

@ -11,8 +11,8 @@ public class App extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("student-list.fxml"));
FXMLLoader fxmlLoader = new FXMLLoader(
App.class.getResource("student-list.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 400, 400);
stage.setTitle("Data");
stage.setScene(scene);


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