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

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

Introduction

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

Prototype

public Writer writer(boolean append) 

Source Link

Document

Returns a writer for writing to this file using the default charset.

Usage

From source file:at.highstreeto.xnllayoutparser.LayoutParser.java

License:Apache License

/**
 *
 * @param layoutFile/*from  w ww .  j av a  2 s . com*/
 * @param actors
 * @throws LayoutParseException
 */
public void save(FileHandle layoutFile, Collection<Actor> actors) throws LayoutParseException {
    try {
        XmlWriter writer = new XmlWriter(layoutFile.writer(false));
        LayoutParserContext context = new LayoutParserContext();
        context.setParsers(parsers);

        writer.element("Layout");

        for (Actor i : actors) {
            parsers.getParserByClass(i.getClass()).save(writer, i, context);
        }

        writer.pop();
        writer.close();
    } catch (IOException e) {
        throw new LayoutParseException(e); // TODO More detailed Exception
    }
}

From source file:com.agateau.utils.CsvWriter.java

License:Apache License

public CsvWriter(FileHandle handle) {
    mWriter = handle.writer(false /* append */);
}

From source file:com.agateau.utils.KeyValueWriter.java

License:Apache License

public KeyValueWriter(FileHandle handle) {
    mWriter = handle.writer(false /* append */);
}

From source file:com.mygdx.game.ichelpers.touchme.SaveHandler.java

public void save(ArrayList<CheckPoint> checkpoints) {
    try {//from  w  w w  .  j a  va  2  s  .  c o m
        StringWriter writer = new StringWriter();
        writer.write("<?xml version = \"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n");
        XmlWriter xml = new XmlWriter(writer);
        XmlWriter racine = xml.element("touchme");
        for (CheckPoint checkpoint : checkpoints) {
            racine.element("checkpoint").element("id").text(checkpoint.getId()).pop().element("position")
                    .element("x").text(checkpoint.getPosition().x).pop().element("y")
                    .text(checkpoint.getPosition().y).pop().element("hauteur").text(checkpoint.getHauteur())
                    .pop().element("largeur").text(checkpoint.getLargeur()).pop().pop().pop();
        }
        racine.pop();
        writer.close();
        FileHandle file = Gdx.files.local("./TouchMe/" + findNewName());
        Writer writer2 = file.writer(false);
        writer2.write(writer.toString());
        writer2.close();
    } catch (IOException ex) {
        Gdx.app.error("SaveHandler", ex.getStackTrace().toString());
    }
}

From source file:com.strongjoshua.console.Log.java

License:Apache License

public boolean printToFile(FileHandle fh) {
    if (fh.isDirectory()) {
        throw new IllegalArgumentException("File cannot be a directory!");
    }/*from ww  w . java 2 s  .c o  m*/

    Writer out = null;
    try {
        out = fh.writer(false);
    } catch (Exception e) {
        return false;
    }

    String toWrite = "";
    for (LogEntry l : logEntries) {
        toWrite += l.toString() + "\n";
    }

    try {
        out.write(toWrite);
        out.close();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.tussle.logging.LibgdxLogHandler.java

License:Open Source License

public LibgdxLogHandler(FileHandle handle) {
    writer = handle.writer(true);
}

From source file:de.thomas.pure_tetris.screens.GameOverScreen.java

License:Open Source License

@Override
public void input(String text) {
    text = text.substring(0, Math.min(text.length(), 10));

    FileHandle file = Gdx.files.local("scores.txt");

    Array<Score> scores = readScores(file);

    if (scores.size > 0) {
        boolean isLast = true;

        for (int x = 0; x < scores.size && x < 10; x++) {
            if (score > scores.get(x).y) {
                scores.insert(x, new Score(text, score));
                isLast = false;/*www.j a  v  a 2 s .  c om*/
                break;
            }
        }

        if (isLast)
            scores.add(new Score(text, score));

        try {
            file.writer(false).write("");
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }

        file = Gdx.files.local("scores.txt");

        int amount = 0;
        for (Score s : scores) {
            if (amount++ >= 10)
                break;

            file.writeString(s.x + " " + s.y + "\n", true);
        }
    } else {
        file.writeString(text + " " + score + "\n", true);
    }

    game.setScreen(new HighScoreScreen(game));
    dispose();
}

From source file:it.alcacoop.backgammon.Main.java

License:Open Source License

@Override
public void shareMatch(MatchRecorder rec) {
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmm");
    Date date = new Date();
    String d = dateFormat.format(date);

    String path = Gdx.files.external("data/gnubg-sgf/match-" + d + ".sgf").path();

    FileHandle fh = Gdx.files.absolute(path);
    Writer writer = fh.writer(false);
    try {//from www . j  a  v  a  2s  .  com
        writer.write(rec.saveSGF());
        writer.flush();
        writer.close();
    } catch (IOException e) {
    }
}

From source file:it.alcacoop.backgammon.utils.JSONProperties.java

License:Open Source License

public void save(FileHandle fh) throws IOException {
    Writer writer = fh.writer(false);
    Json json = new Json();
    json.setOutputType(OutputType.minimal);
    json.toJson(data, writer);/*  ww w  .  j  a v a  2  s  .c  om*/
    writer.flush();
    writer.close();
}

From source file:it.alcacoop.backgammon.utils.MatchRecorder.java

License:Open Source License

public void saveJson(String fname) {
    FileHandle fh = Gdx.files.absolute(fname);
    Writer writer = fh.writer(false);
    Json json = new Json(OutputType.json);
    try {/*from ww w  .j  av  a  2 s .  com*/
        writer.write(json.prettyPrint(this));
        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}