Skip to content

InputStream in ServiceImplementation template should be closed after loading #17

@fishermans

Description

@fishermans

Hi Tobias,

From my point of view, the InputStream should be closed once the Properties have been loaded.:

    private static ServiceImplementation getServiceImplementationByProperty(ServiceImplementation previousConfig, ${ simpleName } serviceImpl) {

        // first try to get config from property file
        final String propertyFileName = "/META-INF/spiap/" + ${ simpleName }.class.getCanonicalName() + "/" + serviceImpl.getClass().getCanonicalName() + ".properties";
        InputStream inputStream = ${ simpleName }ServiceLocator.class.getResourceAsStream(propertyFileName);
        if (inputStream != null) {

            try {
                Properties properties = new Properties();
                properties.load(inputStream);

                String id = properties.getProperty("${constants.id}");
                String description = properties.getProperty("${constants.description}");
                Integer priority = null;
                try {
                    String priorityString = properties.getProperty("${constants.priority}");
                    if (priorityString != null) {
                        priority = Integer.valueOf(priorityString);
                    }
                } catch (NumberFormatException e) {
                    // ignore
                }

                Boolean outOfService = null;
                String outOfServiceString = properties.getProperty("${constants.outOfService}");
                if (outOfServiceString != null) {
                    outOfService = Boolean.valueOf(outOfServiceString);
                }

                return new ServiceImplementation(previousConfig, id, description, priority, outOfService);

            } catch (Exception e) {
                // do nothing
            }
        }

        return previousConfig;

    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions