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, String charset) 

Source Link

Document

Returns a writer for writing to this file.

Usage

From source file:com.bladecoder.engine.model.World.java

License:Apache License

public void saveWorldDesc(FileHandle file) throws IOException {

    float scale = EngineAssetManager.getInstance().getScale();

    Json json = new Json();
    json.setOutputType(OutputType.javascript);

    SerializationHelper.getInstance().setMode(Mode.MODEL);

    json.setWriter(new StringWriter());

    json.writeObjectStart();/*from  w  w w  .j  a v  a2 s  . c  om*/
    json.writeValue("width", width / scale);
    json.writeValue("height", height / scale);
    json.writeValue("initChapter", initChapter);
    verbs.write(json);
    json.writeObjectEnd();

    String s = null;

    if (EngineLogger.debugMode())
        s = json.prettyPrint(json.getWriter().getWriter().toString());
    else
        s = json.getWriter().getWriter().toString();

    Writer w = file.writer(false, "UTF-8");
    w.write(s);
    w.close();
}

From source file:mt.Json.java

License:Apache License

/** @param knownType May be null if the type is unknown.
 * @param elementType May be null if the type is unknown. */
public void toJson(Object object, Class knownType, Class elementType, FileHandle file) {
    Writer writer = null;/*  w  w w.  j a va  2 s . com*/
    try {
        writer = file.writer(false, "UTF-8");
        toJson(object, knownType, elementType, writer);
    } catch (Exception ex) {
        throw new SerializationException("Error writing file: " + file, ex);
    } finally {
        StreamUtils.closeQuietly(writer);
    }
}