Files
SAE32_2022/src/Graphics/Traitable.java

156 lines
3.8 KiB
Java
Raw Normal View History

2023-01-05 05:56:05 +01:00
package Graphics;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStream;
/**
* [Bilal]
* Classe qui sert a stocke les valeurs contenue dans le JSON dans une liste.
*/
public class Traitable {
private final HashMap<String, Object> content;
private final InputStream file;
public Traitable(InputStream file) {
this.content = new HashMap<>();
this.file = file;
this.Run();
}
/**
* Lancement automatique une fois que Traitable est instantie
*
* @see Graphics.GraphicFile
*/
private void Run() {
System.out.println("[+] Preparation...");
try {
try {
StringBuilder allJson = new StringBuilder();
StringBuilder tmp = new StringBuilder();
int i = 0;
for (int cursor = this.file.read(); cursor != -1; cursor = this.file.read()) {
char c = (char) cursor;
allJson.append(c);
}
while (i < allJson.length()) {
if (allJson.charAt(i) == '"') {
while (allJson.charAt(i) != ',') {
tmp.append(allJson.charAt(i));
i++;
}
// System.out.println(this.getNomOfRecord(tmp));
tmp.setLength(0);
}
i++;
}
} catch (StringIndexOutOfBoundsException ignore) {
}
} catch (IOException e) {
System.out.println("[!] Probleme lors de la lecture du fichier");
}
}
private String getNomOfRecord(StringBuilder sb) {
int i = 0;
StringBuilder name = new StringBuilder();
while (i < sb.length()) {
if (sb.charAt(i) == ':') {
return name.toString().replaceAll("\"", "");
}
name.append(sb.charAt(i));
i++;
}
return null;
}
// TODO: a finir (Bilal)
private Object getValueOfRecord(StringBuilder sb) {
// int i;
// int counter;
// StringBuilder value = new StringBuilder();
// String type = "";
// /**
// * Tableau
// */
// if (sb.indexOf("[") != -1) {
// type = "tableau";
// }
// /**
// * Chaine de characteres
// */
// for (i = 0, counter = 0; i <= sb.length() - 1; i++) {
// if (sb.charAt(i) == '"') {
// counter++;
// }
// }
// if (counter < 2 && sb.indexOf(".") != -1) {
// type = "float";
// }
// /*
// * Objet
// */
// if (sb.indexOf("{") != -1) {
// type = "objet";
// }
// /*
// * Integer
// */
// for (i = 0, counter = 0; i <= sb.length() - 1; i++) {
// if (sb.charAt(i) == '"') {
// counter++;
// }
// }
// if (counter < 2) {
// type = "int";
// }
// /**
// * Flottant
// */
// for (i = 0, counter = 0; i <= sb.length() - 1; i++) {
// if (sb.charAt(i) == '"') {
// counter++;
// }
// }
// if (counter < 2 && sb.indexOf(".") != -1) {
// type = "float";
// }
return null;
}
/**
* Ajouter le jeu de cle valeur dans la liste
*
* @param name Nom de la variable
* @param value Contenue de la variable
*/
private void addToList(String name, Object value) {
System.out.println("[+] => " + name + ": " + value);
this.content.put(name, value);
}
public HashMap<String, Object> getVariableMap() {
return this.content;
}
}