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;
/**
* 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;
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());
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();
+ }
}
}
// 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