Created
October 19, 2011 18:19
-
-
Save strangeglyph/1299183 to your computer and use it in GitHub Desktop.
Yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Save the object in form of a .yml file | |
* | |
* @param o The object | |
* @param filename The filename (not including file ending and path) | |
*/ | |
public void save(Object o, String filename) { | |
try { | |
File f = new File(cb.getDataFolder() + "/" + filename + ".yml"); | |
if (!f.exists()) { | |
f.createNewFile(); | |
} | |
yaml.dump(o, new OutputStreamWriter(new FileOutputStream(f))); | |
} catch (IOException ioe) { | |
MsgTools.log(Level.SEVERE, "Unexpected IOError while trying to save object " + o + ", the object might not have been saved", ioe); | |
} | |
} | |
/** | |
* Loads an object from a .yml file | |
* | |
* @param filename The filename (not including file ending and path) | |
* @return The object saved in that file | |
*/ | |
public Object load(String filename) { | |
File f = new File(cb.getDataFolder() + "/" + filename + ".yml"); | |
if (!f.exists()) { | |
return null; | |
} | |
try { | |
return yaml.load(new InputStreamReader(new FileInputStream(f))); | |
} catch (FileNotFoundException fileNotFoundException) { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment