package com.feth.play.plugin.jsonminify;

import java.io.StringWriter;

public class IndentationWriter extends StringWriter {

	/**
	 * The indentation level we are currently in
	 */
	int level = 0;
	
	/**
	 * The newline character
	 */
	final static char NEWLINE = '\n';

	@Override
	public void write(int c) {
		switch (c) {
		case '{':
		case '[':
			level++;
		case ',':
			super.write(c);
			super.write(NEWLINE);
			indent();
			break;
		case '}':
		case ']':
			super.write(NEWLINE);
			level--;
			indent();
		default:
			super.write(c);
			break;
		}
	}

	private void indent() {
		super.write(String.format("%" + (level * 4) + "s", ""));
	}
}

@@ -582,16 +582,35 @@
 ent() %7B%0A
+%09%09if(level %3E 0) %7B%0A%09
 %09%09super.
@@ -660,13 +660,17 @@
 , %22%22));%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A

fix java.util.FormatFlagsConversionMismatchException