Apache Lucene open-source search software
SOLR-1933: 2 space indenting for responses
Yonik Seeley699cbe67c190
diff --git a/solr/src/java/org/apache/solr/response/TextResponseWriter.java b/solr/src/java/org/apache/solr/response/TextResponseWriter.javaindex 456e6619bda..8eb282d0c09 100644--- a/solr/src/java/org/apache/solr/response/TextResponseWriter.java+++ b/solr/src/java/org/apache/solr/response/TextResponseWriter.java@@ -71,28 +71,16 @@ public abstract class TextResponseWriter {/** returns the Writer that the response is being written to */public Writer getWriter() { return writer; }- // use a combination of tabs and spaces to minimize the size of an indented response.- private static final String[] indentArr = new String[] {- "\n",- "\n ",- "\n ",- "\n\t",- "\n\t ",- "\n\t ", // could skip this one (the only 3 char seq)- "\n\t\t",- "\n\t\t "};public void indent() throws IOException {if (doIndent) indent(level);}public void indent(int lev) throws IOException {- int arrsz = indentArr.length-1;- // power-of-two intent array (gratuitous optimization :-)- String istr = indentArr[lev & (indentArr.length-1)];- writer.write(istr);+ writer.write(XMLWriter.indentChars, 0, Math.min((lev<<1)+1, XMLWriter.indentChars.length));}+//// Functions to manipulate the current logical nesting level.// Any indentation will be partially based on level.diff --git a/solr/src/java/org/apache/solr/response/XMLWriter.java b/solr/src/java/org/apache/solr/response/XMLWriter.javaindex 97d7d34ea65..7c77fde0c71 100644--- a/solr/src/java/org/apache/solr/response/XMLWriter.java+++ b/solr/src/java/org/apache/solr/response/XMLWriter.java@@ -283,24 +283,20 @@ final public class XMLWriter {}}- private static final String[] indentArr = new String[] {- "\n",- "\n ",- "\n ",- "\n\t",- "\n\t ",- "\n\t ", // could skip this one (the only 3 char seq)- "\n\t\t" };++ // indent up to 40 spaces+ static final char[] indentChars = new char[81];+ static {+ Arrays.fill(indentChars,' ');+ indentChars[0] = '\n'; // start with a newline+ }public void indent() throws IOException {indent(level);}public void indent(int lev) throws IOException {- int arrsz = indentArr.length-1;- // another option would be lev % arrsz (wrap around)- String istr = indentArr[ lev > arrsz ? arrsz : lev ];- writer.write(istr);+ writer.write(indentChars, 0, Math.min((lev<<1)+1, indentChars.length));}private static final Comparator fieldnameComparator = new Comparator() {