Author: kiwiwings
Date: Wed Mar 16 21:20:15 2016
New Revision: 1735301

URL: http://svn.apache.org/viewvc?rev=1735301&view=rev
Log:
sonar fixes

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java?rev=1735301&r1=1735300&r2=1735301&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java 
Wed Mar 16 21:20:15 2016
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Hashtable;
+import java.util.Map;
 import java.util.StringTokenizer;
 
 import org.apache.poi.util.LocaleUtil;
@@ -42,17 +43,17 @@ public final class ChunkFactory {
        /**
         * Key is a Chunk's type, value is an array of its CommandDefinitions
         */
-       private Hashtable<Integer, CommandDefinition[]> chunkCommandDefinitions 
= 
+       private final Map<Integer, CommandDefinition[]> chunkCommandDefinitions 
= 
              new Hashtable<Integer, CommandDefinition[]>();
        /**
         * What the name is of the chunk table definitions file?
         * This file comes from the scratchpad resources directory.
         */
-       private static String chunkTableName =
+       private static final String chunkTableName =
                "/org/apache/poi/hdgf/chunks_parse_cmds.tbl";
 
        /** For logging problems we spot with the file */
-       private static POILogger logger = 
POILogFactory.getLogger(ChunkFactory.class);
+       private static final POILogger logger = 
POILogFactory.getLogger(ChunkFactory.class);
 
        public ChunkFactory(int version) throws IOException {
                this.version = version;
@@ -77,20 +78,22 @@ public final class ChunkFactory {
                inp = new BufferedReader(new InputStreamReader(cpd, 
LocaleUtil.CHARSET_1252));
                    
                    while( (line = inp.readLine()) != null ) {
-                       if(line.startsWith("#")) continue;
-                       if(line.startsWith(" ")) continue;
-                       if(line.startsWith("\t")) continue;
-                       if(line.length() == 0) continue;
+                       if (line.isEmpty() || "# 
\t".contains(line.substring(0,1))) {
+                           continue;
+                       }
     
                        // Start xxx
-                       if(!line.startsWith("start")) {
+                       if(!line.matches("^start [0-9]+$")) {
                                throw new IllegalStateException("Expecting 
start xxx, found " + line);
                        }
                        int chunkType = Integer.parseInt(line.substring(6));
                        ArrayList<CommandDefinition> defsL = new 
ArrayList<CommandDefinition>();
     
                        // Data entries
-                       while( ! (line = inp.readLine()).startsWith("end") ) {
+                       while( (line = inp.readLine()) != null ) {
+                           if (line.startsWith("end")) {
+                               break;
+                           }
                                StringTokenizer st = new StringTokenizer(line, 
" ");
                                int defType = Integer.parseInt(st.nextToken());
                                int offset = Integer.parseInt(st.nextToken());
@@ -106,8 +109,12 @@ public final class ChunkFactory {
                        chunkCommandDefinitions.put(Integer.valueOf(chunkType), 
defs);
                }
                } finally {
-               if (inp != null) inp.close();
-               if (cpd != null) cpd.close();
+               if (inp != null) {
+                   inp.close();
+               }
+               if (cpd != null) {
+                   cpd.close();
+               }
                }
        }
 
@@ -178,7 +185,9 @@ public final class ChunkFactory {
 
                // Feed in the stuff from  chunks_parse_cmds.tbl
                CommandDefinition[] defs = 
chunkCommandDefinitions.get(Integer.valueOf(header.getType()));
-               if(defs == null) defs = new CommandDefinition[0];
+               if (defs == null) {
+                   defs = new CommandDefinition[0];
+               }
                chunk.commandDefinitions = defs;
 
                // Now get the chunk to process its commands



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to