Skip to content

Commit

Permalink
Use try with resources
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed May 9, 2023
1 parent 5e5e61a commit f6a4226
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/main/java/org/apache/commons/imaging/icc/IccProfileParser.java
Expand Up @@ -50,44 +50,28 @@ public IccProfileInfo getICCProfileInfo(final byte[] bytes) {
}

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);
tag.setData(bytes);
// 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;
}

Expand Down

0 comments on commit f6a4226

Please sign in to comment.