Example usage for com.badlogic.gdx.utils UBJsonWriter close

List of usage examples for com.badlogic.gdx.utils UBJsonWriter close

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils UBJsonWriter close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the underlying output stream and releases any system resources associated with the stream.

Usage

From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java

License:Apache License

/** <p>
 * Convert a text JSON file into binary JSON. The new file will be saved in the same folder as the original one with the
 * {@code gd3b} extension.//from www . ja v  a  2s  . c  om
 * </p>
 * 
 * @param g3djFile Handle to the original G3DJ file.
 * @param overwrite If {@code true} the new file will overwrite any previous file with the same name. Otherwise append a
 *           counter at the end of the file name to make it unique.
 * @throws IOException If there's an exception while reading the input file or writing the output file. */
public void convert(FileHandle g3djFile, boolean overwrite) throws IOException {
    FileHandle newFile = new FileHandle(g3djFile.pathWithoutExtension() + ".g3db");
    int noOverwriteCounter = 0;
    while (!overwrite && newFile.exists()) {
        newFile = new FileHandle(g3djFile.pathWithoutExtension() + "(" + (++noOverwriteCounter) + ").g3db");
    }

    OutputStream fileOutputStream = newFile.write(false);
    UBJsonWriter writer = new UBJsonWriter(fileOutputStream);
    JsonReader reader = new JsonReader();

    try {
        JsonValue root = reader.parse(g3djFile);
        writeObject(root, writer);

    } finally {
        writer.close();
    }
}