Browse Source

add of classes

master
AntonioFrische 2 years ago
parent
commit
74f92519eb
24 changed files with 123 additions and 0 deletions
  1. BIN
      .gradle/7.4/checksums/checksums.lock
  2. BIN
      .gradle/7.4/dependencies-accessors/dependencies-accessors.lock
  3. +0
    -0
      .gradle/7.4/dependencies-accessors/gc.properties
  4. BIN
      .gradle/7.4/executionHistory/executionHistory.bin
  5. BIN
      .gradle/7.4/executionHistory/executionHistory.lock
  6. BIN
      .gradle/7.4/fileChanges/last-build.bin
  7. BIN
      .gradle/7.4/fileHashes/fileHashes.bin
  8. BIN
      .gradle/7.4/fileHashes/fileHashes.lock
  9. BIN
      .gradle/7.4/fileHashes/resourceHashesCache.bin
  10. +0
    -0
      .gradle/7.4/gc.properties
  11. BIN
      .gradle/buildOutputCleanup/buildOutputCleanup.lock
  12. +2
    -0
      .gradle/buildOutputCleanup/cache.properties
  13. BIN
      .gradle/buildOutputCleanup/outputFiles.bin
  14. BIN
      .gradle/file-system.probe
  15. +0
    -0
      .gradle/vcs-1/gc.properties
  16. BIN
      build/classes/java/main/Persona.class
  17. BIN
      build/classes/java/main/SeriableParser.class
  18. BIN
      build/classes/java/main/XmlDomParser.class
  19. BIN
      build/resources/main/Persona.dat
  20. +1
    -0
      build/resources/main/Personas.xml
  21. BIN
      build/tmp/compileJava/previous-compilation-data.bin
  22. +27
    -0
      src/main/java/com/antoniofrische/Persona.java
  23. +35
    -0
      src/main/java/com/antoniofrische/SeriableParser.java
  24. +58
    -0
      src/main/java/com/antoniofrische/XmlDomParser.java

BIN
.gradle/7.4/checksums/checksums.lock View File


BIN
.gradle/7.4/dependencies-accessors/dependencies-accessors.lock View File


+ 0
- 0
.gradle/7.4/dependencies-accessors/gc.properties View File


BIN
.gradle/7.4/executionHistory/executionHistory.bin View File


BIN
.gradle/7.4/executionHistory/executionHistory.lock View File


BIN
.gradle/7.4/fileChanges/last-build.bin View File


BIN
.gradle/7.4/fileHashes/fileHashes.bin View File


BIN
.gradle/7.4/fileHashes/fileHashes.lock View File


BIN
.gradle/7.4/fileHashes/resourceHashesCache.bin View File


+ 0
- 0
.gradle/7.4/gc.properties View File


BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock View File


+ 2
- 0
.gradle/buildOutputCleanup/cache.properties View File

@ -0,0 +1,2 @@
#Tue Nov 08 16:04:08 CET 2022
gradle.version=7.4

BIN
.gradle/buildOutputCleanup/outputFiles.bin View File


BIN
.gradle/file-system.probe View File


+ 0
- 0
.gradle/vcs-1/gc.properties View File


BIN
build/classes/java/main/Persona.class View File


BIN
build/classes/java/main/SeriableParser.class View File


BIN
build/classes/java/main/XmlDomParser.class View File


BIN
build/resources/main/Persona.dat View File


+ 1
- 0
build/resources/main/Personas.xml View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><Personas/>

BIN
build/tmp/compileJava/previous-compilation-data.bin View File


+ 27
- 0
src/main/java/com/antoniofrische/Persona.java View File

@ -0,0 +1,27 @@
package com.antoniofrische;
import java.io.Serializable;
public class Persona implements Serializable {
private String nombre;
private int edad;
public Persona(String nombre, int edad) {
this.nombre = nombre;
this.edad= edad;
}
public Persona() {
this.nombre=null;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
}

+ 35
- 0
src/main/java/com/antoniofrische/SeriableParser.java View File

@ -0,0 +1,35 @@
package com.antoniofrische;
import java.io.*;
public class SeriableParser {
Persona[] personas;
public Persona[] getPersonas() {
return personas;
}
public SeriableParser(File file) {
try(FileInputStream infile = new FileInputStream(file);
ObjectInputStream datos = new ObjectInputStream(infile)){
personas = new Persona[datos.available()];
for (int i = 0; i < datos.available(); i++){
//hace falta un seriable de array y no de persona, tengo que volver a la 8.1
Persona persona = (Persona)datos.readObject();
personas[i] = persona;
}
System.out.println(personas.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException ioe){
ioe.printStackTrace();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}

+ 58
- 0
src/main/java/com/antoniofrische/XmlDomParser.java View File

@ -0,0 +1,58 @@
package com.antoniofrische;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.io.*;
public class XmlDomParser {
public static void main(String[] args) throws IOException{
File f = new File("C:\\Users\\AntonioFrische\\OneDrive - ABACCO Solutions\\Documents\\Schule_22_23_CFGS\\Acceso_Datos\\com.antoniofrische.Persona.dat");
RandomAccessFile raf = new RandomAccessFile(f, "r");
Persona[] personas;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
DOMImplementation implementation = builder.getDOMImplementation();
Document document = implementation.createDocument(null, "Personas", null);
document.setXmlVersion("1.0");
SeriableParser parser = new SeriableParser(f);
personas = parser.getPersonas();
System.out.println(personas.length);
for(int i = 0; i < personas.length; i++) {
System.out.println("Edad: " + personas[i].getEdad() + " NOmbre: " + personas[i].getNombre());
Element raiz = document.createElement("Personas");
document.getDocumentElement().appendChild(raiz);
crearElemento("Edad",Integer.toString(personas[i].getEdad()),raiz,document); // añadir Edad
crearElemento("Nombre",personas[i].getNombre(),raiz,document); // añadir nombre
if (raf.getFilePointer() >= raf.length()) break;
}
Source source = new DOMSource(document);
Result result = new StreamResult (new File("C:\\Users\\AntonioFrische\\OneDrive - ABACCO Solutions\\Documents\\Schule_22_23_CFGS\\Acceso_Datos\\Personas.xml"));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(source,result);
}catch(EOFException eofe) {
System.out.println("Error End Of File: " + eofe.getMessage());
}catch(IOException e) {
System.out.println("Error IO: " + e.getMessage());
}catch(TransformerConfigurationException tce) {
System.out.println("Error Transformer Configuration: " + tce.getMessage());
}catch(TransformerException te) {
System.out.println("Error Transformer: " + te.getMessage());
}catch(ParserConfigurationException pce) {
System.out.println("Error Parser Configuration: " + pce.getMessage());
}finally {
raf.close();
}
}
static void crearElemento(String datoEmpleado, String valor, Element raiz, Document document) {
Element elem = document.createElement (datoEmpleado); //creamos hijo
Text text = document.createTextNode(valor); // damos valor al campo
raiz.appendChild(elem); //pegamos el elemento hijo a la raiz
elem.appendChild(text); //pegamos el valor
}
}

Loading…
Cancel
Save