findbugs: replace switch statement with fall-throughs with if statement, remove duplicate code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751738 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-07-07 00:48:52 +00:00
parent 981d9dabb4
commit 5c43bcf436
1 changed files with 27 additions and 50 deletions

View File

@ -108,58 +108,35 @@ public class HexRead
int characterCount = 0; int characterCount = 0;
byte b = (byte) 0; byte b = (byte) 0;
List<Byte> bytes = new ArrayList<Byte>(); List<Byte> bytes = new ArrayList<Byte>();
boolean done = false; final char a = 'a' - 10;
while ( !done ) final char A = 'A' - 10;
while ( true )
{ {
int count = stream.read(); int count = stream.read();
char baseChar = 'a'; int digitValue = -1;
if ( count == eofChar ) break; if ( '0' <= count && count <= '9' ) {
switch ( count ) digitValue = count - '0';
{ } else if ( 'A' <= count && count <= 'F' ) {
case '#': digitValue = count - A;
readToEOL( stream ); } else if ( 'a' <= count && count <= 'f' ) {
break; digitValue = count - a;
case '0': case '1': case '2': case '3': case '4': case '5': } else if ( '#' == count ) {
case '6': case '7': case '8': case '9': readToEOL( stream );
b <<= 4; } else if ( -1 == count || eofChar == count ) {
b += (byte) ( count - '0' ); break;
characterCount++; }
if ( characterCount == 2 ) // else: ignore the character
{
bytes.add( Byte.valueOf( b ) ); if (digitValue != -1) {
characterCount = 0; b <<= 4;
b = (byte) 0; b += (byte) digitValue;
} characterCount++;
break; if ( characterCount == 2 )
case 'A': {
case 'B': bytes.add( Byte.valueOf( b ) );
case 'C': characterCount = 0;
case 'D': b = (byte) 0;
case 'E': }
case 'F':
baseChar = 'A';
// fall through
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
b <<= 4;
b += (byte) ( count + 10 - baseChar );
characterCount++;
if ( characterCount == 2 )
{
bytes.add( Byte.valueOf( b ) );
characterCount = 0;
b = (byte) 0;
}
break;
case -1:
done = true;
break;
default :
break;
} }
} }
Byte[] polished = bytes.toArray( new Byte[0] ); Byte[] polished = bytes.toArray( new Byte[0] );