This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-imaging.git
The following commit(s) were added to refs/heads/master by this push:
new f6a42262 Use try with resources
f6a42262 is described below
commit f6a42262ff472e59e0347d9f030b36e36a2ee21e
Author: Gary Gregory <[email protected]>
AuthorDate: Tue May 9 17:32:47 2023 -0400
Use try with resources
---
.../commons/imaging/icc/IccProfileParser.java | 34 ++++++----------------
1 file changed, 9 insertions(+), 25 deletions(-)
diff --git a/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
b/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
index 20e22e75..a78bffc0 100644
--- a/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
+++ b/src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
@@ -50,21 +50,16 @@ public class IccProfileParser extends BinaryFileParser {
}
public IccProfileInfo getICCProfileInfo(final ByteSource byteSource) {
-
- InputStream is = null;
-
+ // TODO Throw instead of logging?
+ final IccProfileInfo result;
+ try (InputStream is = byteSource.getInputStream()) {
+ result = readICCProfileInfo(is);
+ } catch (final Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ return null;
+ }
+ //
try {
-
- is = byteSource.getInputStream();
- final IccProfileInfo result = readICCProfileInfo(is);
-
- if (result == null) {
- return null;
- }
-
- is.close();
- is = null;
-
for (final IccTag tag : result.getTags()) {
final byte[] bytes = byteSource.getBlock(tag.offset,
tag.length);
// Debug.debug("bytes: " + bytes.length);
@@ -72,22 +67,11 @@ public class IccProfileParser extends BinaryFileParser {
// tag.dump("\t" + i + ": ");
}
// result.fillInTagData(byteSource);
-
return result;
} catch (final Exception e) {
// Debug.debug("Error: " + file.getAbsolutePath());
LOGGER.log(Level.SEVERE, e.getMessage(), e);
- } finally {
- try {
- if (is != null) {
- is.close();
- }
- } catch (final Exception e) {
- LOGGER.log(Level.SEVERE, e.getMessage(), e);
- }
-
}
-
return null;
}