Skip to content

Commit

Permalink
NIFI-7167 This closes #4486. Fixing resource leaks in IdentifyMimeType
Browse files Browse the repository at this point in the history
The TikaInputStream and FileInputStream instances utilized in IdentifyMimeType are now explicitly closed. The FileInputStream is additionally wrapped by a BufferedInputStream.

Signed-off-by: Joe Witt <joewitt@apache.org>
  • Loading branch information
Cameron E. Tidd authored and joewitt committed Sep 2, 2020
1 parent c3cab48 commit 9a1ae46
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -177,8 +177,9 @@ public void setup(final ProcessContext context) {
}

} else {
try {
this.detector = MimeTypesFactory.create(new FileInputStream(configFile));
try (final FileInputStream fis = new FileInputStream(configFile);
final InputStream bis = new BufferedInputStream(fis)) {
this.detector = MimeTypesFactory.create(bis);
this.mimeTypes = (MimeTypes)this.detector;
} catch (Exception e) {
context.yield();
Expand Down Expand Up @@ -212,8 +213,8 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
session.read(flowFile, new InputStreamCallback() {
@Override
public void process(final InputStream stream) throws IOException {
try (final InputStream in = new BufferedInputStream(stream)) {
TikaInputStream tikaStream = TikaInputStream.get(in);
try (final InputStream in = new BufferedInputStream(stream);
final TikaInputStream tikaStream = TikaInputStream.get(in)) {
Metadata metadata = new Metadata();

if (filename != null && context.getProperty(USE_FILENAME_IN_DETECTION).asBoolean()) {
Expand Down

0 comments on commit 9a1ae46

Please sign in to comment.