Write the contents of the JSONObject as JSON text to a writer. Warning: This method assumes that the data structure is acyclical. @return The writer. @throws RuntimeException
(Writer writer, int indentFactor, int indent)
| 1870 | * @throws RuntimeException |
| 1871 | */ |
| 1872 | protected Writer writeInternal(Writer writer, int indentFactor, int indent) { |
| 1873 | try { |
| 1874 | boolean commanate = false; |
| 1875 | final int length = this.size(); |
| 1876 | Iterator keys = this.keyIterator(); |
| 1877 | writer.write('{'); |
| 1878 | |
| 1879 | int actualFactor = (indentFactor == -1) ? 0 : indentFactor; |
| 1880 | |
| 1881 | if (length == 1) { |
| 1882 | Object key = keys.next(); |
| 1883 | writer.write(quote(key.toString())); |
| 1884 | writer.write(':'); |
| 1885 | if (actualFactor > 0) { |
| 1886 | writer.write(' '); |
| 1887 | } |
| 1888 | //writeValue(writer, this.map.get(key), actualFactor, indent); |
| 1889 | writeValue(writer, this.map.get(key), indentFactor, indent); |
| 1890 | } else if (length != 0) { |
| 1891 | final int newIndent = indent + actualFactor; |
| 1892 | while (keys.hasNext()) { |
| 1893 | Object key = keys.next(); |
| 1894 | if (commanate) { |
| 1895 | writer.write(','); |
| 1896 | } |
| 1897 | if (indentFactor != -1) { |
| 1898 | writer.write('\n'); |
| 1899 | } |
| 1900 | indent(writer, newIndent); |
| 1901 | writer.write(quote(key.toString())); |
| 1902 | writer.write(':'); |
| 1903 | if (actualFactor > 0) { |
| 1904 | writer.write(' '); |
| 1905 | } |
| 1906 | //writeValue(writer, this.map.get(key), actualFactor, newIndent); |
| 1907 | writeValue(writer, this.map.get(key), indentFactor, newIndent); |
| 1908 | commanate = true; |
| 1909 | } |
| 1910 | if (indentFactor != -1) { |
| 1911 | writer.write('\n'); |
| 1912 | } |
| 1913 | indent(writer, indent); |
| 1914 | } |
| 1915 | writer.write('}'); |
| 1916 | return writer; |
| 1917 | } catch (IOException exception) { |
| 1918 | throw new RuntimeException(exception); |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | |
| 1923 | // // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
no test coverage detected