/**
* Loads a previously serialized object from a given file using YAML.
*
* @param file File to load from
* @param clazz Class the object should be of
* @param exists Whether or not the file exists and the expensive
* {@link File#exists()} operation can be skipped
* @return The deserialized object, or null if the file does not exist
* @throws IllegalArgumentException If the file or class is null
* @throws IOException If the file cannot be read
* @throws InvalidConfigurationException If the given file is not a valid
* YAML configuration
* @see #save(ConfigurationSerializable, File)
*/
@SuppressWarnings("unchecked")
public static <T extends ConfigurationSerializable> T load(File file, Class<T> clazz, boolean exists) throws IOException, InvalidConfigurationException
{
Validate.notNull(file, "file cannot be null!");
Validate.notNull(clazz, "clazz cannot be null!");
if (! exists && ! file.exists())
return null;
YamlConfiguration config = new YamlConfiguration();
config.load(file);
Map<String, Object> map = config.getValues(true);
return (T) ConfigurationSerialization.deserializeObject(map, clazz);
}
FileSerialization.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:SwornAPI
作者:
评论列表
文章目录