Changeset a67ea4b for apps/jetty


Ignore:
Timestamp:
Dec 9, 2017 1:02:17 AM (2 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
4512a94
Parents:
fe5e4a2
Message:

Cleanups: Close resources via try-finally

We can't use try-with-resources until we bump the minimum-supported Android
version for the client library to API 19.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/jetty/java/src/net/i2p/jetty/JettyStart.java

    rfe5e4a2 ra67ea4b  
    11package net.i2p.jetty;
     2
     3import java.io.IOException;
    24
    35// Contains code from org.mortbay.xml.XmlConfiguation:
     
    1820
    1921import java.io.InputStream;
     22import java.net.URL;
    2023import java.util.ArrayList;
    2124import java.util.Arrays;
     
    8083        Properties properties=new Properties();
    8184        XmlConfiguration last=null;
    82         InputStream in = null;
     85        Resource r = null;
    8386        for (int i = 0; i < args.length; i++) {
    8487            if (args[i].toLowerCase().endsWith(".properties")) {
    85                 in = Resource.newResource(args[i]).getInputStream();
    86                 properties.load(in);
    87                 in.close();
     88                try {
     89                    r = Resource.newResource(args[i]);
     90                    properties.load(r.getInputStream());
     91                } finally {
     92                    if (r != null) r.close();
     93                }
    8894            } else {
    89                 XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(args[i]).getURL());
     95                URL configUrl;
     96                try {
     97                    r = Resource.newResource(args[i]);
     98                    configUrl = r.getURL();
     99                } finally {
     100                    if (r != null) r.close();
     101                }
     102                XmlConfiguration configuration = new XmlConfiguration(configUrl);
    90103                if (last!=null)
    91104                    configuration.getIdMap().putAll(last.getIdMap());
Note: See TracChangeset for help on using the changeset viewer.