Skip to content

Commit

Permalink
Minor warnings clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 26, 2021
1 parent 1f7e58c commit 11ae44d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 47 deletions.
76 changes: 36 additions & 40 deletions src/main/java/com/fasterxml/aalto/in/Utf32Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -203,10 +201,10 @@ public int read(char[] cbuf, int start, int len) throws IOException
}

/*
////////////////////////////////////////
// Internal methods
////////////////////////////////////////
*/
/**********************************************************************
/* Internal methods
/**********************************************************************
*/


/**
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -277,9 +273,9 @@ public final void freeBuffers()
}

/*
//////////////////////////////////////////
// Error reporting
//////////////////////////////////////////
/**********************************************************************
/* Error reporting
/**********************************************************************
*/

private void reportUnexpectedEOF(int gotBytes, int needed)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/fasterxml/aalto/util/XmlNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/fasterxml/aalto/sax/TestEntityResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/com/fasterxml/aalto/sax/TestSaxReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -35,7 +34,7 @@ public void testPI()

/*
//////////////////////////////////////////////////////
// Helper methods:
// Helper methods
//////////////////////////////////////////////////////
*/

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/stax2/wstream/TestClosing.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ final static class MyResult
{
final MyWriter mWriter;

private MyResult() {
MyResult() {
super();
mWriter = new MyWriter();
setWriter(mWriter);
Expand Down

0 comments on commit 11ae44d

Please sign in to comment.