Java Code Examples for com.badlogic.gdx.files.FileHandle#readBytes()

The following examples show how to use com.badlogic.gdx.files.FileHandle#readBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserDataHelper.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
private void loadKey() {
    if (key != null)
        return;
    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();
    }
}
 
Example 2
Source File: Recorder.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
private Array<Snapshot> loadBytes() {
	String filename = "history.dat";
	FileHandle histFile = Gdx.files.external(demoDir + filename);
	if (!histFile.exists()) {
		Log.error("playback history file doesn't exist, skip loading: " + filename);
		return null;
	}
	byte[] bytes = histFile.readBytes();
	int len = bytes.length;
	Log.debug("history files bytes: " + len);
	if (len % Snapshot.SNAPSHOT_SIZE != 0) {
		Log.error("playback history length error, expected divisible by: " + Snapshot.SNAPSHOT_SIZE + ", remainder: " + len % Snapshot.SNAPSHOT_SIZE);
		return null;
	}
	Array<Snapshot> snapshots = new Array<>();
	int bytesProcessed = 0;
	while (bytesProcessed < len) {
		snapshots.add(Snapshot.deserialize(bytes, bytesProcessed));
		bytesProcessed += Snapshot.SNAPSHOT_SIZE;
	}
	return snapshots;
}
 
Example 3
Source File: Recorder.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private Array<Snapshot> loadJson() {
	Json json = new Json();
	String filename = demoDir + "history.json.gz";
	FileHandle histFile = Gdx.files.external(filename);
	if (!histFile.exists()) {
		Log.error("playback history file doesn't exist, skip loading: " + filename);
		return null;
	}
	byte[] bytes = histFile.readBytes();
	String data = Compression.decompressToString(bytes);
	System.out.println(data);
	return (Array<Snapshot>) json.fromJson(Array.class, data);
}
 
Example 4
Source File: FreeType.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public Face newFace(FileHandle font, int faceIndex) {
	byte[] data = font.readBytes();
	return newMemoryFace(data, data.length, faceIndex);
}
 
Example 5
Source File: Palette.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public static Palette loadFromFile(FileHandle file) {
  byte[] data = file.readBytes();
  return loadFromArray(data);
}
 
Example 6
Source File: Index.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public static Index loadFromFile(FileHandle file) {
  byte[] data = file.readBytes();
  return loadFromArray(file.toString(), data);
}