sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1735301 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-03-16 21:20:15 +00:00
parent 80e4d8b879
commit ac6a01898d

View File

@ -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