List of usage examples for com.badlogic.gdx.files FileHandle writeBytes
public void writeBytes(byte[] bytes, boolean append)
From source file:com.sidereal.dolphinoes.architecture.core.GameData.java
License:Apache License
/** Saves the object as a file at root/dataName by serialising it * /*w w w.j a v a 2 s .co m*/ * @param dataName * The name of the file path relative to the Data Folder, as well as the key used for {@link #data} * @param obj * The value of the object. WIll be the data in the file, as well as the value of the entry that the * object takes in {@link #data} * <p> * Passing a null object as a parameter will only make the folders */ public final void save(String dataName, Object obj, boolean loadOnStartup, boolean storeInMemory) { if (storageType.equals(StorageType.None)) return; String path = rootDataPath + "/" + dataName; getFileHandle(path.substring(0, path.lastIndexOf("/"))).mkdirs(); if (obj == null) return; // we are done with creating nested files. try { FileHandle file = getFileHandle(rootDataPath + dataName + ".dd"); file.writeBytes(serialize(obj), false); if (storeInMemory) data.put(dataName, obj); // not in the list of files in the system, add it there. if (!exists(dataName)) filePaths.add(dataName); this.loadOnStartup.put(dataName, new BooleanWrapper(loadOnStartup)); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.vlaaad.dice.UserDataHelper.java
License:Open Source License
private void loadKey() { if (key != null) return;// ww w.j a v a 2 s . co m FileHandle keyFile = Gdx.files.local("app.key"); if (!keyFile.exists()) { try { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); key = keyGenerator.generateKey().getEncoded(); keyFile.writeBytes(key, false); } catch (Exception e) { Logger.log("failed to load key", e); } } else { key = keyFile.readBytes(); } }
From source file:dk.sidereal.lumm.architecture.core.AppData.java
License:Apache License
/** * Saves the object as a file at root/dataName by serialising it * * @param dataName// w w w.j av a2 s . c o m * The name of the file path relative to the Data Folder, as well * as the key used for {@link #data} * @param obj * The value of the object. WIll be the data in the file, as well * as the value of the entry that the object takes in * {@link #data} * <p> * Passing a null object as a parameter will only make the * folders */ public final void save(String dataName, Object obj, boolean loadOnStartup, boolean storeInMemory) { if (storageType.equals(StorageType.None)) return; String path = rootDataPath + "/" + dataName; getFileHandle(path.substring(0, path.lastIndexOf("/"))).mkdirs(); if (obj == null) return; // we are done with creating nested files. try { FileHandle file = getFileHandle(rootDataPath + dataName + ".dd"); file.writeBytes(serialize(obj), false); Lumm.debug.log("Saved object to file at path \"" + rootDataPath + dataName + ".dd" + "\"", null); if (storeInMemory) { data.put(dataName, obj); } // not in the list of files in the system, add it there. if (!exists(dataName)) filePaths.add(dataName); // load on startup won't update itself with its' own startup // information, we return. if (dataName.equals(LOAD_ON_STARTUP_PATH)) return; if (!this.loadOnStartup.containsKey(dataName) || this.loadOnStartup.get(dataName) != loadOnStartup) { this.loadOnStartup.put(dataName, new Boolean(loadOnStartup)); save(LOAD_ON_STARTUP_PATH, this.loadOnStartup, false, true); } } catch (IOException e) { e.printStackTrace(); } }