All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.usmanhussain.ghost.JSONWriter Maven / Gradle / Ivy

Go to download

com.usmanhussain.ghost - Ghost is an AI project aimed at the testing community. Ghost is a project to help reduce test failure analysis and will later on evolve to auto fix simple maintenance errors. Designed, Developed, Implemented and Loved by Mr Usman H Hussain

There is a newer version: 1.0.6
Show newest version
package com.usmanhussain.ghost;

import java.io.StringWriter;

/**
 * http://code.google.com/p/json-simple/issues/detail?id=22
 * http://code.google.com/p/json-simple/issues/attachmentText?id=22&aid=220009000&name=JSonWriter.java&token=JFPBdQPSUs1cIM6Bl0KdKxP5BUs%3A1397646495589
 *
 * @author Elad Tabak
 * @version 0.1
 * @since 28-Nov-2011
 */
public class JSONWriter extends StringWriter {

    private int indent = 0;

    @Override
    public void write(int c) {
        if (((char) c) == '[' || ((char) c) == '{') {
            super.write(c);
            super.write('\n');
            indent++;
            writeIndentation();
        } else if (((char) c) == ',') {
            super.write(c);
            super.write('\n');
            writeIndentation();
        } else if (((char) c) == ']' || ((char) c) == '}') {
            super.write('\n');
            indent--;
            writeIndentation();
            super.write(c);
        } else {
            super.write(c);
        }
    }

    private void writeIndentation() {
        for (int i = 0; i < indent; i++) {
            super.write("   ");
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy