From 77f062c9424843bf856be698fb75d6d32b8792b0 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Wed, 16 Mar 2016 21:20:15 +0000 Subject: [PATCH] sonar fixes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1735301 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hdgf/chunks/ChunkFactory.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java index 8bd8f5c20a..819051ff13 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java @@ -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 chunkCommandDefinitions = + private final Map chunkCommandDefinitions = new Hashtable(); /** * 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 defsL = new ArrayList(); // 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 -- 2.39.5