NIFI-7167 This closes #4486. Fixing resource leaks in IdentifyMimeType

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>
This commit is contained in:
Cameron E. Tidd 2020-08-20 20:56:00 -04:00 committed by Joe Witt
parent c3cab48325
commit 9a1ae469d8
No known key found for this signature in database
GPG Key ID: 9093BF854F811A1A
1 changed files with 5 additions and 4 deletions

View File

@ -177,8 +177,9 @@ public class IdentifyMimeType extends AbstractProcessor {
}
} 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();
@ -212,8 +213,8 @@ public class IdentifyMimeType extends AbstractProcessor {
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()) {