JAML/src/main/java/tech/nevets/jaml/util/ProfileUtils.java

33 lines
1.0 KiB
Java

package tech.nevets.jaml.util;
import com.google.gson.*;
import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Profile;
import java.io.*;
import java.nio.file.Path;
public class ProfileUtils {
private static final Path PROFILE_PATH = Path.of(JAML.path + "\\profiles\\");
public static void createProfile(Profile profile) throws IOException {
String profileName = profile.getProfileName();
Writer writer = new FileWriter(PROFILE_PATH + "\\" + profileName + ".json");
GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
String jsonString = gson.toJson(profile);
writer.write(jsonString);
writer.close();
loadProfile(profileName);
}
public static Profile loadProfile(String profileName) throws FileNotFoundException {
BufferedReader reader = new BufferedReader(new FileReader(PROFILE_PATH + "\\" + profileName + ".json"));
return new Gson().fromJson(reader, Profile.class);
}
}