diff --git a/src/main/java/com/fasterxml/aalto/in/Utf32Reader.java b/src/main/java/com/fasterxml/aalto/in/Utf32Reader.java index ffe6c64..3794b9e 100644 --- a/src/main/java/com/fasterxml/aalto/in/Utf32Reader.java +++ b/src/main/java/com/fasterxml/aalto/in/Utf32Reader.java @@ -17,20 +17,18 @@ import java.io.*; - -import com.fasterxml.aalto.in.ReaderConfig; import com.fasterxml.aalto.util.XmlConsts; /** * Since JDK does not come with UTF-32/UCS-4, let's implement a simple * decoder to use. */ -public final class Utf32Reader +public class Utf32Reader extends Reader { - final static char NULL_CHAR = (char) 0; + private final static char NULL_CHAR = (char) 0; - final ReaderConfig mConfig; + protected final ReaderConfig mConfig; protected InputStream mIn; @@ -39,44 +37,44 @@ public final class Utf32Reader protected int mPtr; protected int mLength; - final boolean mBigEndian; + protected final boolean mBigEndian; /** * Although input is fine with full Unicode set, Java still uses * 16-bit chars, so we may have to split high-order chars into * surrogate pairs. */ - char mSurrogate = NULL_CHAR; + protected char mSurrogate = NULL_CHAR; /** * Total read character count; used for error reporting purposes */ - int mCharCount = 0; + protected int mCharCount = 0; /** * Total read byte count; used for error reporting purposes */ - int mByteCount = 0; + protected int mByteCount = 0; /* - //////////////////////////////////////// - // Life-cycle - //////////////////////////////////////// - */ + /********************************************************************** + /* Life-cycle + /********************************************************************** + */ public Utf32Reader(ReaderConfig cfg, InputStream in, - byte[] buf, int ptr, int len, - boolean isBigEndian) + byte[] buf, int ptr, int len, + boolean isBigEndian) { mConfig = cfg; mBigEndian = isBigEndian; } /* - //////////////////////////////////////// - // Reader API - //////////////////////////////////////// - */ + /********************************************************************** + /* Reader API + /********************************************************************** + */ @Override public void close() throws IOException @@ -110,10 +108,10 @@ public int read() throws IOException } /* - //////////////////////////////////////// - // Public API - //////////////////////////////////////// - */ + /********************************************************************** + /* Public API + /********************************************************************** + */ @Override public int read(char[] cbuf, int start, int len) throws IOException @@ -203,10 +201,10 @@ public int read(char[] cbuf, int start, int len) throws IOException } /* - //////////////////////////////////////// - // Internal methods - //////////////////////////////////////// - */ + /********************************************************************** + /* Internal methods + /********************************************************************** + */ /** @@ -230,9 +228,8 @@ private boolean loadMore(int available) } mLength = available; } else { - /* Ok; here we can actually reasonably expect an EOF, - * so let's do a separate read right away: - */ + // Ok; here we can actually reasonably expect an EOF, + // so let's do a separate read right away: mPtr = 0; int count = mIn.read(mBuffer); if (count < 1) { @@ -247,9 +244,8 @@ private boolean loadMore(int available) mLength = count; } - /* Need at least 4 bytes; if we don't get that many, it's an - * error. - */ + // Need at least 4 bytes; if we don't get that many, it's an + // error. while (mLength < 4) { int count = mIn.read(mBuffer, mLength, mBuffer.length - mLength); if (count < 1) { @@ -277,9 +273,9 @@ public final void freeBuffers() } /* - ////////////////////////////////////////// - // Error reporting - ////////////////////////////////////////// + /********************************************************************** + /* Error reporting + /********************************************************************** */ private void reportUnexpectedEOF(int gotBytes, int needed) @@ -289,8 +285,8 @@ private void reportUnexpectedEOF(int gotBytes, int needed) int charPos = mCharCount; throw new CharConversionException("Unexpected EOF in the middle of a 4-byte UTF-32 char: got " - +gotBytes+", needed "+needed - +", at char #"+charPos+", byte #"+bytePos+")"); + +gotBytes+", needed "+needed + +", at char #"+charPos+", byte #"+bytePos+")"); } private void reportInvalid(int value, int offset, String msg) @@ -300,8 +296,8 @@ private void reportInvalid(int value, int offset, String msg) int charPos = mCharCount + offset; throw new CharConversionException("Invalid UTF-32 character 0x" - +Integer.toHexString(value) - +msg+" at char #"+charPos+", byte #"+bytePos+")"); + +Integer.toHexString(value) + +msg+" at char #"+charPos+", byte #"+bytePos+")"); } protected void reportBounds(char[] cbuf, int start, int len) diff --git a/src/main/java/com/fasterxml/aalto/util/XmlNames.java b/src/main/java/com/fasterxml/aalto/util/XmlNames.java index d77c950..4aa089e 100644 --- a/src/main/java/com/fasterxml/aalto/util/XmlNames.java +++ b/src/main/java/com/fasterxml/aalto/util/XmlNames.java @@ -87,7 +87,8 @@ private static boolean validSurrogateNameChar(char firstChar, char sec) return false; } // And the composite, is it ok? - int val = ((firstChar - 0xD800) << 10) + 0x10000; +// int val = ((firstChar - 0xD800) << 10) + 0x10000; + // 04-Jan-2021, tatu: As per lgtm.com's warning, yes, due to range checks // for first and second char, cannot exceed maximum // if (val > XmlConsts.MAX_UNICODE_CHAR) { diff --git a/src/test/java/com/fasterxml/aalto/sax/TestEntityResolver.java b/src/test/java/com/fasterxml/aalto/sax/TestEntityResolver.java index ef02a90..fa2f118 100644 --- a/src/test/java/com/fasterxml/aalto/sax/TestEntityResolver.java +++ b/src/test/java/com/fasterxml/aalto/sax/TestEntityResolver.java @@ -7,8 +7,6 @@ import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; -import com.fasterxml.aalto.sax.*; - /** * Simple unit tests to verify that most fundamental parsing functionality * works via Woodstox SAX implementation. diff --git a/src/test/java/com/fasterxml/aalto/sax/TestSaxReader.java b/src/test/java/com/fasterxml/aalto/sax/TestSaxReader.java index c694a61..d7839de 100644 --- a/src/test/java/com/fasterxml/aalto/sax/TestSaxReader.java +++ b/src/test/java/com/fasterxml/aalto/sax/TestSaxReader.java @@ -4,12 +4,11 @@ import java.io.StringReader; import javax.xml.parsers.SAXParser; + import org.xml.sax.*; import org.xml.sax.ext.DeclHandler; import org.xml.sax.ext.DefaultHandler2; -import com.fasterxml.aalto.sax.*; - public class TestSaxReader extends base.BaseTestCase { @@ -35,7 +34,7 @@ public void testPI() /* ////////////////////////////////////////////////////// - // Helper methods: + // Helper methods ////////////////////////////////////////////////////// */ diff --git a/src/test/java/stax2/wstream/TestClosing.java b/src/test/java/stax2/wstream/TestClosing.java index 5a837a1..0e28369 100644 --- a/src/test/java/stax2/wstream/TestClosing.java +++ b/src/test/java/stax2/wstream/TestClosing.java @@ -207,7 +207,7 @@ final static class MyResult { final MyWriter mWriter; - private MyResult() { + MyResult() { super(); mWriter = new MyWriter(); setWriter(mWriter);