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)
| 1816 | * @throws RuntimeException |
| 1817 | */ |
| 1818 | protected Writer writeInternal(Writer writer, int indentFactor, int indent) { |
| 1819 | try { |
| 1820 | boolean commanate = false; |
| 1821 | final int length = this.size(); |
| 1822 | Iterator keys = this.keyIterator(); |
| 1823 | writer.write('{'); |
| 1824 | |
| 1825 | int actualFactor = (indentFactor == -1) ? 0 : indentFactor; |
| 1826 | |
| 1827 | if (length == 1) { |
| 1828 | Object key = keys.next(); |
| 1829 | writer.write(quote(key.toString())); |
| 1830 | writer.write(':'); |
| 1831 | if (actualFactor > 0) { |
| 1832 | writer.write(' '); |
| 1833 | } |
| 1834 | //writeValue(writer, this.map.get(key), actualFactor, indent); |
| 1835 | writeValue(writer, this.map.get(key), indentFactor, indent); |
| 1836 | } else if (length != 0) { |
| 1837 | final int newIndent = indent + actualFactor; |
| 1838 | while (keys.hasNext()) { |
| 1839 | Object key = keys.next(); |
| 1840 | if (commanate) { |
| 1841 | writer.write(','); |
| 1842 | } |
| 1843 | if (indentFactor != -1) { |
| 1844 | writer.write('\n'); |
| 1845 | } |
| 1846 | indent(writer, newIndent); |
| 1847 | writer.write(quote(key.toString())); |
| 1848 | writer.write(':'); |
| 1849 | if (actualFactor > 0) { |
| 1850 | writer.write(' '); |
| 1851 | } |
| 1852 | //writeValue(writer, this.map.get(key), actualFactor, newIndent); |
| 1853 | writeValue(writer, this.map.get(key), indentFactor, newIndent); |
| 1854 | commanate = true; |
| 1855 | } |
| 1856 | if (indentFactor != -1) { |
| 1857 | writer.write('\n'); |
| 1858 | } |
| 1859 | indent(writer, indent); |
| 1860 | } |
| 1861 | writer.write('}'); |
| 1862 | return writer; |
| 1863 | } catch (IOException exception) { |
| 1864 | throw new RuntimeException(exception); |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | |
| 1869 | // // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
no test coverage detected