[ 
https://issues.apache.org/jira/browse/ARIES-1730?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jean-Baptiste Onofré reassigned ARIES-1730:
-------------------------------------------

    Assignee: Jean-Baptiste Onofré

> It is better to close a file stream with 
> -----------------------------------------
>
>                 Key: ARIES-1730
>                 URL: https://issues.apache.org/jira/browse/ARIES-1730
>             Project: Aries
>          Issue Type: Improvement
>          Components: JMX
>    Affects Versions: jmx-1.1.6
>            Reporter: Hao Zhong
>            Assignee: Jean-Baptiste Onofré
>            Priority: Minor
>
> The Framework_installBundleFromURL method has the following code:
> {code}
>  try {
>             inputStream = createStream(url);
>             Bundle bundle = context.installBundle(location, inputStream);
>             return bundle.getBundleId();
>         } catch (Exception e) {
>             IOException ioex = new IOException("Installation of a bundle with 
> location " + location + " failed with the message: " + e.getMessage());
>             ioex.initCause(e);
>             throw ioex;
>         } finally {
>             if (inputStream != null) {
>                 try {
>                     inputStream.close();
>                 } catch (IOException ioe) {
>                 }
>             }
>         }
> {code}
> Here, the method handles the inputStream by itself. It is better to use the 
> implemented method in org.apache.aries.application.utils.filesystem.IOUtils. 
> Indeed, ARIES-622 fixed a similar problem. The original code is:
> {code}
> public DeploymentMetadata parseDeploymentMetadata(IFile src) throws 
> IOException
>   {
>     InputStream is = src.open();
>     try {
>       return parseDeploymentMetadata(is);
>     } finally {
>       is.close();
>     }
>   }
> {code}
> The fixed code is
> {code}
> import org.apache.aries.application.utils.filesystem.IOUtils;
> ...
> public DeploymentMetadata parseDeploymentMetadata(IFile src) throws 
> IOException
>   {
>     InputStream is = src.open();
>     try {
>       return parseDeploymentMetadata(is);
>     } finally {
>       IOUtils.close(is);
>     }
>   }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to