Example usage for com.badlogic.gdx.files FileHandle readBytes

List of usage examples for com.badlogic.gdx.files FileHandle readBytes

Introduction

In this page you can find the example usage for com.badlogic.gdx.files FileHandle readBytes.

Prototype

public byte[] readBytes() 

Source Link

Document

Reads the entire file into a byte array.

Usage

From source file:com.heartpirates.harthsip.AsapRadio.java

License:Open Source License

private void loadMusic(String path) {
    FileHandle handle = Gdx.files.internal(path);

    if (!handle.exists()) {
        Gdx.app.debug("Radio", "Music file not found.");
    } else {//  ww  w .  j  av a  2  s  .  com
        Gdx.app.debug("Radio", "Music loaded.");
        byte[] bytes = handle.readBytes();
        loadAsapMusic(path, bytes, bytes.length);
        this.nowPlaying = path;
    }
}

From source file:com.intrepid.nicge.utilz.animation.AnimationPackLoader.java

@Override
public AnimationPack loadSync(AssetManager manager, String fileName, FileHandle file,
        AnimationPackParameter parameter) {
    byte[] bytes = file.readBytes();
    String json = null;/* w  w w.  j  ava 2s.com*/
    if (ENCODED)
        json = new String(Base64.getDecoder().decode(bytes));
    else
        json = new String(bytes);
    AnimationPackInfo animationPackInfo = new Json().fromJson(AnimationPackInfo.class, json);

    String texturePath = "resources/textures/" + file.nameWithoutExtension() + ".png";
    Texture texture = manager.get(texturePath, Texture.class);

    return new AnimationPack(animationPackInfo, texture);
}

From source file:com.md.crypto.PixmapCrypto.java

License:Apache License

/**
 * Creates a new Pixmap instance from the given file. The file must be a
 * Png, Jpeg or Bitmap. Paletted formats are not supported.
 * /* w ww.  j  ava  2s  .  c  o  m*/
 * @param file
 *            the {@link FileHandle}
 */
public PixmapCrypto(FileHandle file) {
    try {
        byte[] bytes = file.readBytes();
        long currentTime = System.currentTimeMillis();
        //         XorEncrypto.encrypt(bytes, 10);
        //         XorEncrypto.decryp(bytes, 10);
        XXTEACrypto.encrypt(bytes, Config.keysEn);
        XXTEACrypto.decrypt(bytes, Config.keysDe);
        System.out.println("timeDE: " + (System.currentTimeMillis() - currentTime));
        pixmap = new Gdx2DPixmap(bytes, 0, bytes.length, 0);
    } catch (Exception e) {
        throw new GdxRuntimeException("Couldn't load file: " + file, e);
    }
}

From source file:com.vlaaad.dice.UserDataHelper.java

License:Open Source License

UserData loadUserData() {
    FileHandle data = Gdx.files.local("game.save");
    boolean newUserData = false;
    InputStream inputStream;/*from w w w  .j av  a  2s . c om*/
    if (!data.exists()) {
        data = Gdx.files.internal("initial-game-data.yml");
        newUserData = true;
        inputStream = data.read();
    } else {
        if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
            UserData result = UserData.deserialize(new Yaml().load(data.read()));
            if (!result.tutorialCompleted) {
                result = UserData
                        .deserialize(new Yaml().load(Gdx.files.internal("initial-game-data.yml").read()));
            }
            return result;
        }
        //file exists, decode
        loadKey();
        if (key == null) {
            inputStream = data.read();
        } else {
            try {
                byte[] stringData = decrypt(key, data.readBytes());
                inputStream = new ByteArrayInputStream(stringData);
            } catch (Exception e) {
                Logger.error("failed to decrypt data", e);
                inputStream = data.read();
            }
        }
    }
    Object raw = new Yaml().load(inputStream);
    if (raw == null) {
        return UserData.deserialize(new Yaml().load(Gdx.files.internal("initial-game-data.yml").read()));
    }
    UserData result = UserData.deserialize(raw);
    if (!newUserData && !result.tutorialCompleted) {
        result = UserData.deserialize(new Yaml().load(Gdx.files.internal("initial-game-data.yml").read()));
    }
    return result;
}

From source file:com.vlaaad.dice.UserDataHelper.java

License:Open Source License

private void loadKey() {
    if (key != null)
        return;/* www.  j av  a  2  s  . c  o  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:de.tomgrill.gdxfacebook.core.GDXFacebookMultiPartRequest.java

License:Apache License

@Override
public InputStream getContentStream() throws IOException {
    ByteArrayOutputStream op = new ByteArrayOutputStream();

    if (fileHandles.size > 1) {

        // TODO this part is not yet used. See issue #13 @github
        String groupBoundary = generateBoundary();
        String openGroup = "";
        openGroup += "--" + boundary + "\r\n";
        openGroup += "Content-Disposition: form-data; name=\"files\"" + "\r\n";
        openGroup += "Content-Type: multipart/mixed; boundary=" + groupBoundary + "\r\n";

        op.write(openGroup.getBytes());/*  w w  w.  j  a v a  2 s  . c  o m*/

        for (int i = 0; i < fileHandles.size; i++) {
            FileHandle fileHandle = fileHandles.get(i);

            String fileString = "";
            fileString += "\r\n" + "--" + groupBoundary + "\r\n";
            fileString += "Content-Disposition: file; filename=\"" + fileHandle.name() + "\"" + "\r\n";
            fileString += "Content-Type: image/png" + "\r\n";
            fileString += "Content-Transfer-Encoding: binary" + "\r\n";
            fileString += "\r\n";

            op.write(fileString.getBytes());
            op.write(loadFile(fileHandle));

            if (i + 1 == fileHandles.size) {
                fileString = "\r\n" + "--" + groupBoundary + "--";
                op.write(fileString.getBytes());
            }

        }

    } else {
        for (int i = 0; i < fileHandles.size; i++) {
            FileHandle fileHandle = fileHandles.get(i);
            String contentType = contentTypes.get(i);
            String fileString = "";
            fileString += "--" + boundary + "\r\n";
            fileString += "Content-Disposition: form-data; name=\"files" + i + "\"; filename=\""
                    + fileHandle.name() + "\"" + "\r\n";
            fileString += "Content-Type: " + contentType + "\r\n";
            fileString += "Content-Transfer-Encoding: binary" + "\r\n";
            fileString += "\r\n";

            op.write(fileString.getBytes());
            op.write(fileHandle.readBytes());

        }
    }

    for (int i = 0; i < fields.size; i++) {

        String key = fields.getKeyAt(i);
        String value = fields.getValueAt(i);

        String fieldString = "";
        fieldString += "\r\n" + "--" + boundary + "\r\n";
        fieldString += "Content-Disposition: form-data; name=\"" + key + "\"" + "\r\n";
        fieldString += "Content-Type: text/plain; charset=UTF-8" + "\r\n";
        fieldString += "\r\n";
        fieldString += value;

        if (i + 1 == fields.size) {
            fieldString += "\r\n" + "--" + boundary + "--" + "\r\n";
        }

        op.write(fieldString.getBytes());
    }

    return new ByteArrayInputStream(op.toByteArray());
}

From source file:MeshBoneUtil.CreatureModuleUtils.java

License:Open Source License

public static CreatureFlatDataJava.rootData LoadCreatureFlatData(String filename_in) {
    FileHandle file = Gdx.files.internal(filename_in);
    byte[] rawBytes = file.readBytes();

    ByteBuffer bb = ByteBuffer.wrap(rawBytes);
    return CreatureFlatDataJava.rootData.getRootAsrootData(bb);
}