Skip to content

Commit

Permalink
NIFI-7167 This closes apache#4486. Fixing resource leaks in IdentifyM…
Browse files Browse the repository at this point in the history
…imeType

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 driesva committed Mar 19, 2021
1 parent 4fb9d17 commit cb2fb6c
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 cb2fb6c

Please sign in to comment.