From 63fb8f8472bebd7b28fbb642648326fa361e937b Mon Sep 17 00:00:00 2001 From: joehni Date: Wed, 27 Sep 2023 21:03:06 +0200 Subject: [PATCH] Reformat. --- .../xstream/io/xml/PrettyPrintWriter.java | 37 +++++----- .../xstream/io/xml/PrettyPrintWriterTest.java | 71 ++++++++++--------- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/xstream/src/java/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java b/xstream/src/java/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java index a504785a5..aa7ef98c8 100644 --- a/xstream/src/java/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java +++ b/xstream/src/java/com/thoughtworks/xstream/io/xml/PrettyPrintWriter.java @@ -6,7 +6,7 @@ * The software in this package is published under the terms of the BSD * style license a copy of which has been included with this distribution in * the LICENSE.txt file. - * + * * Created on 07. March 2004 by Joe Walnes */ package com.thoughtworks.xstream.io.xml; @@ -38,14 +38,14 @@ * neither directly nor as entity nor within CDATA. However, this writer works by default in a quirks mode, where it * will write any character at least as character entity (even a null character). You may switch into XML_1_1 mode * (which supports most characters) or XML_1_0 that does only support a very limited number of control characters. See - * XML specification for version 1.0 or 1.1. If a character is not supported, a + * XML specification for version 1.0 or + * 1.1. If a character is not supported, a * {@link StreamException} is thrown. Select a proper parser implementation that respects the version in the XML header - * (the Xpp3 parser will also read character entities of normally invalid characters). - * You may also switch to XML_1_0_REPLACEMENT or XML_1_1_REPLACEMENT mode, which will replace the invalid characters - * with a U+FFFD replacement character. + * (the Xpp3 or MX parsers will also read character entities of normally invalid characters). You may also switch to + * XML_1_0_REPLACEMENT or XML_1_1_REPLACEMENT mode, which will replace the invalid characters with a U+FFFD replacement + * character. *

- * + * * @author Joe Walnes * @author Jörg Schaible */ @@ -80,7 +80,8 @@ public class PrettyPrintWriter extends AbstractXmlWriter { /** * @since 1.4 */ - public PrettyPrintWriter(final Writer writer, final int mode, final char[] lineIndenter, final NameCoder nameCoder) { + public PrettyPrintWriter( + final Writer writer, final int mode, final char[] lineIndenter, final NameCoder nameCoder) { super(nameCoder); this.writer = new QuickWriter(writer); this.lineIndenter = lineIndenter; @@ -259,8 +260,8 @@ private void writeText(final String text, final boolean isAttribute) { replaced = true; } else { throw new StreamException("Invalid character 0x" - + Integer.toHexString(c) - + " in XML stream"); + + Integer.toHexString(c) + + " in XML stream"); } } } @@ -270,14 +271,18 @@ private void writeText(final String text, final boolean isAttribute) { } else { boolean replaced = false; if (mode == XML_1_0 || mode == XML_1_0_REPLACEMENT) { - if (c < 9 || c == '\u000b' || c == '\u000c' || c == '\u000e' || c >= '\u000f' && c <= '\u001f') { + if (c < 9 + || c == '\u000b' + || c == '\u000c' + || c == '\u000e' + || c >= '\u000f' && c <= '\u001f') { if (mode == XML_1_0_REPLACEMENT) { writer.write(REPLACEMENT); replaced = true; } else { throw new StreamException("Invalid character 0x" - + Integer.toHexString(c) - + " in XML 1.0 stream"); + + Integer.toHexString(c) + + " in XML 1.0 stream"); } } } @@ -288,8 +293,8 @@ private void writeText(final String text, final boolean isAttribute) { replaced = true; } else { throw new StreamException("Invalid character 0x" - + Integer.toHexString(c) - + " in XML stream"); + + Integer.toHexString(c) + + " in XML stream"); } } } @@ -355,7 +360,7 @@ public void close() { /** * Retrieve the line terminator. This method returns always a line feed, since according the XML specification any * parser must ignore a carriage return. Overload this method, if you need different behavior. - * + * * @return the line terminator * @since 1.3 */ diff --git a/xstream/src/test/com/thoughtworks/xstream/io/xml/PrettyPrintWriterTest.java b/xstream/src/test/com/thoughtworks/xstream/io/xml/PrettyPrintWriterTest.java index 3ba459020..c63cd602d 100644 --- a/xstream/src/test/com/thoughtworks/xstream/io/xml/PrettyPrintWriterTest.java +++ b/xstream/src/test/com/thoughtworks/xstream/io/xml/PrettyPrintWriterTest.java @@ -259,16 +259,16 @@ public void testReplacesInvalidControlCharactersInXml1_0ReplacementMode() { writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_0_REPLACEMENT); writer.startNode("tag"); final String ctrl = "" - + "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" - + "\u0008\u0009\n\u000b\u000c\r\u000e\u000f" - + "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" - + "\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f" - + "\u007f" - + "\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087" - + "\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f" - + "\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097" - + "\u0098\u0099\u009a\u009b\u009c\u009d\u009e\u009f" - + ""; + + "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" + + "\u0008\u0009\n\u000b\u000c\r\u000e\u000f" + + "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" + + "\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f" + + "\u007f" + + "\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087" + + "\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f" + + "\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097" + + "\u0098\u0099\u009a\u009b\u009c\u009d\u009e\u009f" + + ""; for (int i = 0; i < ctrl.length(); i++) { final char c = ctrl.charAt(i); writer.setValue(new Character(c).toString()); @@ -276,42 +276,43 @@ public void testReplacesInvalidControlCharactersInXml1_0ReplacementMode() { writer.endNode(); assertXmlProducedIs("��������" - + "�\t\n�� ��" - + "��������" - + "��������" - + "" - + "€‚ƒ„…†‡" - + "ˆ‰Š‹ŒŽ" - + "‘’“”•–—" - + "˜™š›œžŸ"); } + + "�\t\n�� ��" + + "��������" + + "��������" + + "" + + "€‚ƒ„…†‡" + + "ˆ‰Š‹ŒŽ" + + "‘’“”•–—" + + "˜™š›œžŸ"); + } public void testReplacesInvalidControlCharactersInXml1_1ReplacementMode() { writer = new PrettyPrintWriter(buffer, PrettyPrintWriter.XML_1_1_REPLACEMENT); writer.startNode("tag"); final String ctrl = "" - + "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" - + "\u0008\u0009\n\u000b\u000c\r\u000e\u000f" - + "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" - + "\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f" - + "\u007f" - + "\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087" - + "\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f" - + "\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097" - + "\u0098\u0099\u009a\u009b\u009c\u009d\u009e\u009f" - + ""; + + "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" + + "\u0008\u0009\n\u000b\u000c\r\u000e\u000f" + + "\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017" + + "\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f" + + "\u007f" + + "\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087" + + "\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f" + + "\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097" + + "\u0098\u0099\u009a\u009b\u009c\u009d\u009e\u009f" + + ""; for (int i = 0; i < ctrl.length(); i++) { final char c = ctrl.charAt(i); writer.setValue(new Character(c).toString()); } writer.endNode(); assertXmlProducedIs("�" - + "\t\n " - + "" - + "" - + "€‚ƒ„…†‡" - + "ˆ‰Š‹ŒŽ" - + "‘’“”•–—" - + "˜™š›œžŸ"); + + "\t\n " + + "" + + "" + + "€‚ƒ„…†‡" + + "ˆ‰Š‹ŒŽ" + + "‘’“”•–—" + + "˜™š›œžŸ"); } public void testSupportsInvalidUnicodeCharacterslInQuirksMode() {