Browse files

fixed hardcoded max limit of indent level

  • Loading branch information...
1 parent bedd1e7 commit 30a7d108607c92b021f3b156b3d9f22bfc9f1c94 @michelegonella committed Oct 26, 2012
Showing with 14 additions and 4 deletions.
  1. +14 −4 zen-dataobject/src/main/java/com/nominanuda/dataobject/JsonPrinter.java
View
18 zen-dataobject/src/main/java/com/nominanuda/dataobject/JsonPrinter.java
@@ -4,8 +4,6 @@
import java.io.Writer;
import java.util.Stack;
-import org.xml.sax.SAXException;
-
import com.nominanuda.lang.Maths;
import static com.nominanuda.dataobject.DataType.*;
@@ -134,20 +132,32 @@ public Cx(DataType t) {
}
}
private int indent = 0;
- private String[] d = new String[] {
+ private final static String[] INDENTS = new String[] {
""," "," "," "," "," "," "
};
//TODO
private void indent() throws RuntimeException {
if(pretty) {
try {
w.write("\n");
- w.write(d[indent]);
+ w.write(indentSpaces(indent));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
+ private String indentSpaces(int size) {
+ if(size < INDENTS.length) {
+ return INDENTS[size];
+ } else {
+ char[] carr = new char[size];
+ for(int i = 0; i < size; i++) {
+ carr[i] = ' ';
+ }
+ return new String(carr);
+ }
+ }
+
private class CommaInsCtx implements JsonContentHandler {
Stack<Cx> stack = new Stack<Cx>();

0 comments on commit 30a7d10

Please sign in to comment.