NIFI-1035 AbstractKiteProcessor.getSchema leaks file handles. closes #101.

Close file handles when reading schema from resources or paths in AbstractKiteProcessor.getSchema

Signed-off-by: joewitt <joewitt@apache.org>
This commit is contained in:
Alan Jackoway 2015-10-12 15:30:20 -07:00 committed by joewitt
parent 22924c656b
commit 943ccfedef
1 changed files with 7 additions and 4 deletions

View File

@ -121,14 +121,17 @@ abstract class AbstractKiteProcessor extends AbstractProcessor {
if ("dataset".equals(uri.getScheme()) || "view".equals(uri.getScheme())) { if ("dataset".equals(uri.getScheme()) || "view".equals(uri.getScheme())) {
return Datasets.load(uri).getDataset().getDescriptor().getSchema(); return Datasets.load(uri).getDataset().getDescriptor().getSchema();
} else if ("resource".equals(uri.getScheme())) { } else if ("resource".equals(uri.getScheme())) {
InputStream in = Resources.getResource(uri.getSchemeSpecificPart()) try (InputStream in = Resources.getResource(uri.getSchemeSpecificPart())
.openStream(); .openStream()) {
return parseSchema(uri, in); return parseSchema(uri, in);
}
} else { } else {
// try to open the file // try to open the file
Path schemaPath = new Path(uri); Path schemaPath = new Path(uri);
FileSystem fs = schemaPath.getFileSystem(conf); FileSystem fs = schemaPath.getFileSystem(conf);
return parseSchema(uri, fs.open(schemaPath)); try (InputStream in = fs.open(schemaPath)) {
return parseSchema(uri, in);
}
} }
} catch (DatasetNotFoundException e) { } catch (DatasetNotFoundException e) {