aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorJaven O'Neal <onealj@apache.org>2016-07-07 00:48:52 +0000
committerJaven O'Neal <onealj@apache.org>2016-07-07 00:48:52 +0000
commit5c43bcf4363ea1f0497dcc70963543fa4137a0b9 (patch)
treee2e871520c636e6b1861e1a1c18b63dbe1ce7fa8 /src/java
parent981d9dabb4007f69335cab176c3536d8e788ff5b (diff)
downloadpoi-5c43bcf4363ea1f0497dcc70963543fa4137a0b9.tar.gz
poi-5c43bcf4363ea1f0497dcc70963543fa4137a0b9.zip
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
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/poi/util/HexRead.java77
1 files changed, 27 insertions, 50 deletions
diff --git a/src/java/org/apache/poi/util/HexRead.java b/src/java/org/apache/poi/util/HexRead.java
index 8e5ee7f939..165ad03135 100644
--- a/src/java/org/apache/poi/util/HexRead.java
+++ b/src/java/org/apache/poi/util/HexRead.java
@@ -108,58 +108,35 @@ public class HexRead
int characterCount = 0;
byte b = (byte) 0;
List<Byte> bytes = new ArrayList<Byte>();
- boolean done = false;
- while ( !done )
+ final char a = 'a' - 10;
+ final char A = 'A' - 10;
+ while ( true )
{
int count = stream.read();
- char baseChar = 'a';
- if ( count == eofChar ) break;
- switch ( count )
- {
- case '#':
- readToEOL( stream );
- break;
- case '0': case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- b <<= 4;
- b += (byte) ( count - '0' );
- characterCount++;
- if ( characterCount == 2 )
- {
- bytes.add( Byte.valueOf( b ) );
- characterCount = 0;
- b = (byte) 0;
- }
- break;
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- 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;
+ int digitValue = -1;
+ if ( '0' <= count && count <= '9' ) {
+ digitValue = count - '0';
+ } else if ( 'A' <= count && count <= 'F' ) {
+ digitValue = count - A;
+ } else if ( 'a' <= count && count <= 'f' ) {
+ digitValue = count - a;
+ } else if ( '#' == count ) {
+ readToEOL( stream );
+ } else if ( -1 == count || eofChar == count ) {
+ break;
+ }
+ // else: ignore the character
+
+ if (digitValue != -1) {
+ b <<= 4;
+ b += (byte) digitValue;
+ characterCount++;
+ if ( characterCount == 2 )
+ {
+ bytes.add( Byte.valueOf( b ) );
+ characterCount = 0;
+ b = (byte) 0;
+ }
}
}
Byte[] polished = bytes.toArray( new Byte[0] );