Minor clean-up.

This commit is contained in:
Harald Kuhr 2021-12-10 13:33:28 +01:00
parent 511a29beb9
commit 6653f4a85d
2 changed files with 19 additions and 30 deletions

View File

@ -29,6 +29,9 @@
package com.twelvemonkeys.xml; package com.twelvemonkeys.xml;
import java.io.OutputStream;
import java.io.Writer;
import org.w3c.dom.DOMConfiguration; import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMImplementationList; import org.w3c.dom.DOMImplementationList;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -38,9 +41,6 @@ import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSOutput; import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSSerializer; import org.w3c.dom.ls.LSSerializer;
import java.io.OutputStream;
import java.io.Writer;
/** /**
* {@code DOMImplementationLS} backed implementation. * {@code DOMImplementationLS} backed implementation.
* *
@ -88,17 +88,6 @@ public final class DOMSerializer {
output.setCharacterStream(pStream); output.setCharacterStream(pStream);
} }
/*
// TODO: Is it useful?
public void setNewLine(final String pNewLine) {
serializer.setNewLine(pNewLine);
}
public String getNewLine() {
return serializer.getNewLine();
}
*/
/** /**
* Specifies wether the serializer should use indentation and optimize for * Specifies wether the serializer should use indentation and optimize for
* readability. * readability.
@ -169,13 +158,7 @@ public final class DOMSerializer {
try { try {
return DOMImplementationRegistry.newInstance(); return DOMImplementationRegistry.newInstance();
} }
catch (ClassNotFoundException e) { catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
catch (InstantiationException e) {
throw new IllegalStateException(e);
}
catch (IllegalAccessException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
} }

View File

@ -30,16 +30,23 @@
package com.twelvemonkeys.xml; package com.twelvemonkeys.xml;
import com.twelvemonkeys.lang.StringUtil; import java.io.ByteArrayInputStream;
import org.w3c.dom.*; import java.io.ByteArrayOutputStream;
import org.xml.sax.SAXException; import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.Date;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.nio.charset.Charset; import org.w3c.dom.*;
import java.util.Date; import org.xml.sax.SAXException;
import com.twelvemonkeys.lang.StringUtil;
/** /**
* XMLSerializer * XMLSerializer
@ -290,7 +297,7 @@ public class XMLSerializer {
} }
private static int appendAndEscape(final String pString, int pStart, final int pEnd, final StringBuilder pBuilder, final String pEntity) { private static int appendAndEscape(final String pString, int pStart, final int pEnd, final StringBuilder pBuilder, final String pEntity) {
pBuilder.append(pString.substring(pStart, pEnd)); pBuilder.append(pString, pStart, pEnd);
pBuilder.append(pEntity); pBuilder.append(pEntity);
return pEnd + 1; return pEnd + 1;
} }
@ -527,8 +534,7 @@ public class XMLSerializer {
builder = factory.newDocumentBuilder(); builder = factory.newDocumentBuilder();
} }
catch (ParserConfigurationException e) { catch (ParserConfigurationException e) {
//noinspection ThrowableInstanceNeverThrown BOGUS throw new IOException(e);
throw (IOException) new IOException(e.getMessage()).initCause(e);
} }
DOMImplementation dom = builder.getDOMImplementation(); DOMImplementation dom = builder.getDOMImplementation();