use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.
the class TestFileHandleResolver method resolve.
@Override
public FileHandle resolve(String fileName) {
URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
File file = new File(url.getPath());
return new FileHandle(file);
}
use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.
the class ProfileManagerGDX method persist.
@Override
public void persist(P profile) {
FileHandle profileDataFile = Gdx.files.local(preferencesManager.PROFILE_DATA_FILE);
Json json = new Json();
String profileAsText = json.toJson(profile);
profileAsText = Base64Coder.encodeString(profileAsText);
profileDataFile.writeString(profileAsText, false);
}
use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.
the class ProfileManagerGDX method retrieveProfile.
@Override
public P retrieveProfile() {
FileHandle profileDataFile = Gdx.files.local(preferencesManager.PROFILE_DATA_FILE);
Json json = new Json();
if (profileDataFile.exists()) {
try {
String profileAsText = profileDataFile.readString().trim();
if (profileAsText.matches("^[A-Za-z0-9/+=]+$")) {
profileAsText = Base64Coder.decodeString(profileAsText);
}
profile = (P) json.fromJson(profile.getClass(), profileAsText);
} catch (Exception e) {
FileHandle initProfileDataFile = Gdx.files.internal(preferencesManager.INIT_PROFILE_DATA_FILE);
profile = (P) json.fromJson(profile.getClass(), initProfileDataFile.readString().trim());
persist(profile);
}
} else {
FileHandle initProfileDataFile = Gdx.files.internal(preferencesManager.INIT_PROFILE_DATA_FILE);
profile = (P) json.fromJson(profile.getClass(), initProfileDataFile.readString().trim());
persist(profile);
}
return profile;
}
use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.
the class Preloader method list.
public FileHandle[] list(String url, String suffix) {
Array<FileHandle> files = new Array<FileHandle>();
for (String path : texts.keys()) {
if (isChild(path, url) && path.endsWith(suffix)) {
files.add(new GwtFileHandle(this, path, FileType.Internal));
}
}
FileHandle[] list = new FileHandle[files.size];
System.arraycopy(files.items, 0, list, 0, list.length);
return list;
}
use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.
the class I18NBundle method loadBundle.
// Tries to load the bundle for the given locale.
private static I18NBundle loadBundle(FileHandle baseFileHandle, String encoding, Locale targetLocale) {
I18NBundle bundle = null;
Reader reader = null;
try {
FileHandle fileHandle = toFileHandle(baseFileHandle, targetLocale);
if (checkFileExistence(fileHandle)) {
// Instantiate the bundle
bundle = new I18NBundle();
// Load bundle properties from the stream with the specified encoding
reader = fileHandle.reader(encoding);
bundle.load(reader);
}
} catch (IOException e) {
throw new GdxRuntimeException(e);
} finally {
StreamUtils.closeQuietly(reader);
}
if (bundle != null) {
bundle.setLocale(targetLocale);
}
return bundle;
}
Aggregations