Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed hardcoded max limit of indent level

  • Loading branch information...
commit 30a7d108607c92b021f3b156b3d9f22bfc9f1c94 1 parent bedd1e7
@michelegonella authored
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,7 +132,7 @@ public Cx(DataType t) {
}
}
private int indent = 0;
- private String[] d = new String[] {
+ private final static String[] INDENTS = new String[] {
""," "," "," "," "," "," "
};
//TODO
@@ -142,12 +140,24 @@ 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>();
Please sign in to comment.
Something went wrong with that request. Please try again.