aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-10-24 21:25:52 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-10-24 21:25:52 +0000
commit90bfac52d607c6a8499bfefe17d12d74253e5b7a (patch)
tree5fa940937c99a62fd667f8629d384496079b67da /src/scratchpad
parentebdd3c37d42166c1318f819b37af23eb1ebb6a2e (diff)
downloadpoi-90bfac52d607c6a8499bfefe17d12d74253e5b7a.tar.gz
poi-90bfac52d607c6a8499bfefe17d12d74253e5b7a.zip
Sonar fixes - a few "Try-with-resources should be used"
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882820 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java80
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java13
2 files changed, 39 insertions, 54 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 5ebda3841d..9c5087350e 100644
--- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
+++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
@@ -72,55 +72,45 @@ public final class ChunkFactory {
* of all the different possible chunk commands.
*/
private void processChunkParseCommands() throws IOException {
- String line;
- InputStream cpd = null;
- BufferedReader inp = null;
- try {
- cpd = ChunkFactory.class.getResourceAsStream(chunkTableName);
+ try (InputStream cpd = ChunkFactory.class.getResourceAsStream(chunkTableName)) {
if(cpd == null) {
throw new IllegalStateException("Unable to find HDGF chunk definition on the classpath - " + chunkTableName);
}
- inp = new BufferedReader(new InputStreamReader(cpd, LocaleUtil.CHARSET_1252));
-
- while( (line = inp.readLine()) != null ) {
- if (line.isEmpty() || "# \t".contains(line.substring(0,1))) {
- continue;
- }
-
- // Start xxx
- 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<>();
-
- // Data entries
- 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());
- String name = st.nextToken("\uffff").substring(1);
-
- CommandDefinition def = new CommandDefinition(defType,offset,name);
- defsL.add(def);
- }
-
- CommandDefinition[] defs = defsL.toArray(new CommandDefinition[0]);
-
- // Add to the map
- chunkCommandDefinitions.put(chunkType, defs);
- }
- } finally {
- if (inp != null) {
- inp.close();
- }
- if (cpd != null) {
- cpd.close();
- }
+ try (BufferedReader inp = new BufferedReader(new InputStreamReader(cpd, LocaleUtil.CHARSET_1252))) {
+ String line;
+ while ((line = inp.readLine()) != null) {
+ if (line.isEmpty() || "# \t".contains(line.substring(0, 1))) {
+ continue;
+ }
+
+ // Start xxx
+ 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<>();
+
+ // Data entries
+ 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());
+ String name = st.nextToken("\uffff").substring(1);
+
+ CommandDefinition def = new CommandDefinition(defType, offset, name);
+ defsL.add(def);
+ }
+
+ CommandDefinition[] defs = defsL.toArray(new CommandDefinition[0]);
+
+ // Add to the map
+ chunkCommandDefinitions.put(chunkType, defs);
+ }
+ }
}
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
index d616180245..b6453cab80 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
@@ -173,16 +173,11 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
* Constructs a new, empty, Powerpoint document.
*/
public static HSLFSlideShowImpl create() {
- InputStream is = HSLFSlideShowImpl.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt");
- if (is == null) {
- throw new HSLFException("Missing resource 'empty.ppt'");
- }
- try {
- try {
- return new HSLFSlideShowImpl(is);
- } finally {
- is.close();
+ try (InputStream is = HSLFSlideShowImpl.class.getResourceAsStream("/org/apache/poi/hslf/data/empty.ppt")) {
+ if (is == null) {
+ throw new HSLFException("Missing resource 'empty.ppt'");
}
+ return new HSLFSlideShowImpl(is);
} catch (IOException e) {
throw new HSLFException(e);
}