Changeset e77409e


Ignore:
Timestamp:
Nov 25, 2013 11:14:09 PM (7 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
0347c56
Parents:
615ba94
Message:

Close resources

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java

    r615ba94 re77409e  
    3838        Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
    3939        int count = 0;
    40         FileInputStream in = null;
     40        BufferedReader br = null;
    4141        try {
    42             in = new FileInputStream(file);
    43             BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
     42            br = new BufferedReader(new InputStreamReader(
     43                        new FileInputStream(file), "ISO-8859-1"));
    4444            String line = null;
    4545            while ( (line = br.readLine()) != null) {
     
    6262                log.warn("Error reading the DHT File", ioe);
    6363        } finally {
    64             if (in != null) try { in.close(); } catch (IOException ioe) {}
     64            if (br != null) try { br.close(); } catch (IOException ioe) {}
    6565        }
    6666        if (log.shouldLog(Log.INFO))
  • apps/sam/java/src/net/i2p/sam/SAMBridge.java

    r615ba94 re77409e  
    215215        synchronized (nameToPrivKeys) {
    216216            nameToPrivKeys.clear();
    217             FileInputStream in = null;
     217            BufferedReader br = null;
    218218            try {
    219                 in = new FileInputStream(persistFilename);
    220                 BufferedReader reader = new BufferedReader(new InputStreamReader(in));
     219                br = new BufferedReader(new InputStreamReader(
     220                        new FileInputStream(persistFilename)));
    221221                String line = null;
    222                 while ( (line = reader.readLine()) != null) {
     222                while ( (line = br.readLine()) != null) {
    223223                    int eq = line.indexOf('=');
    224224                    String name = line.substring(0, eq);
     
    231231                _log.error("Unable to read the keys from " + persistFilename, ioe);
    232232            } finally {
    233                 if (in != null) try { in.close(); } catch (IOException ioe) {}
     233                if (br != null) try { br.close(); } catch (IOException ioe) {}
    234234            }
    235235        }
  • router/java/src/net/i2p/router/Blocklist.java

    r615ba94 re77409e  
    216216        int peercount = 0;
    217217        long ipcount = 0;
    218         FileInputStream in = null;
     218        BufferedReader br = null;
    219219        try {
    220             in = new FileInputStream(BLFile);
    221             BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
     220            br = new BufferedReader(new InputStreamReader(
     221                    new FileInputStream(BLFile), "UTF-8"));
    222222            String buf = null;
    223223            while ((buf = br.readLine()) != null && count < maxSize) {
     
    248248            return;
    249249        } finally {
    250             if (in != null) try { in.close(); } catch (IOException ioe) {}
     250            if (br != null) try { br.close(); } catch (IOException ioe) {}
    251251        }
    252252
     
    406406        if ( (!BLFile.exists()) || (BLFile.length() <= 0) ) return 0;
    407407        int lines = 0;
    408         FileInputStream in = null;
     408        BufferedReader br = null;
    409409        try {
    410             in = new FileInputStream(BLFile);
    411             BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
     410            br = new BufferedReader(new InputStreamReader(
     411                    new FileInputStream(BLFile), "ISO-8859-1"));
    412412            while (br.readLine() != null) {
    413413                lines++;
     
    418418            return 0;
    419419        } finally {
    420             if (in != null) try { in.close(); } catch (IOException ioe) {}
     420            if (br != null) try { br.close(); } catch (IOException ioe) {}
    421421        }
    422422        return lines;
     
    771771            byte ip[] = iter.next();
    772772            int ipint = toInt(ip);
    773             FileInputStream in = null;
     773            BufferedReader br = null;
    774774            try {
    775                 in = new FileInputStream(BLFile);
    776                 BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
     775                br = new BufferedReader(new InputStreamReader(
     776                        new FileInputStream(BLFile), "UTF-8"));
    777777                String buf = null;
    778778                // assume the file is unsorted, so go through the whole thing
     
    783783                    }
    784784                    if (match(ipint, toEntry(e.ip1, e.ip2))) {
    785                         try { in.close(); } catch (IOException ioe) {}
     785                        try { br.close(); } catch (IOException ioe) {}
    786786                        String reason = _x("IP banned by blocklist.txt entry {0}");
    787787                        // only one translate parameter for now
     
    802802                    _log.warn("Error reading the BLFile", ioe);
    803803            } finally {
    804                 if (in != null) try { in.close(); } catch (IOException ioe) {}
     804                if (br != null) try { br.close(); } catch (IOException ioe) {}
    805805            }
    806806        }
  • router/java/src/net/i2p/router/MultiRouter.java

    r615ba94 re77409e  
    6868        if (!scan.hasNextInt()) {
    6969            usage();
     70            scan.close();
    7071            return;
    7172        }
     
    7374        if (nbrRouters < 0) {
    7475            usage();
     76            scan.close();
    7577            return;
    7678        }
     79        scan.close();
    7780       
    7881        _out = System.out;
  • router/java/src/net/i2p/router/transport/GeoIP.java

    r615ba94 re77409e  
    195195            return;
    196196        }
    197         FileInputStream in = null;
     197        BufferedReader br = null;
    198198        try {
    199             in = new FileInputStream(geoFile);
    200             BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
     199            br = new BufferedReader(new InputStreamReader(
     200                    new FileInputStream(geoFile), "UTF-8"));
    201201            String line = null;
    202202            while ( (line = br.readLine()) != null) {
     
    216216                _log.error("Error reading the Country File", ioe);
    217217        } finally {
    218             if (in != null) try { in.close(); } catch (IOException ioe) {}
     218            if (br != null) try { br.close(); } catch (IOException ioe) {}
    219219        }
    220220    }
     
    257257        int idx = 0;
    258258        long start = _context.clock().now();
    259         FileInputStream in = null;
     259        BufferedReader br = null;
    260260        try {
    261             in = new FileInputStream(geoFile);
    262261            String buf = null;
    263             BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
     262            br = new BufferedReader(new InputStreamReader(
     263                    new FileInputStream(geoFile), "ISO-8859-1"));
    264264            while ((buf = br.readLine()) != null && idx < search.length) {
    265265                try {
     
    289289                _log.error("Error reading the geoFile", ioe);
    290290        } finally {
    291             if (in != null) try { in.close(); } catch (IOException ioe) {}
     291            if (br != null) try { br.close(); } catch (IOException ioe) {}
    292292        }
    293293
  • router/java/src/net/i2p/router/transport/GeoIPv6.java

    r615ba94 re77409e  
    159159            int count = 0;
    160160            InputStream in = null;
     161            BufferedReader br = null;
    161162            try {
    162163                in = new BufferedInputStream(new FileInputStream(geoFile));
     
    164165                    in = new GZIPInputStream(in);
    165166                String buf = null;
    166                 BufferedReader br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
     167                br = new BufferedReader(new InputStreamReader(in, "ISO-8859-1"));
    167168                while ((buf = br.readLine()) != null) {
    168169                    try {
     
    192193            } finally {
    193194                if (in != null) try { in.close(); } catch (IOException ioe) {}
     195                if (br != null) try { br.close(); } catch (IOException ioe) {}
    194196            }
    195197        }
  • router/java/src/net/i2p/router/util/EventLog.java

    r615ba94 re77409e  
    44import java.io.File;
    55import java.io.FileInputStream;
    6 import java.io.InputStream;
    76import java.io.InputStreamReader;
    87import java.io.IOException;
     
    117116        }
    118117        rv = new TreeMap<Long, String>();
    119         InputStream in = null;
     118        BufferedReader br = null;
    120119        try {
    121             in = new FileInputStream(_file);
    122             BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
     120            br = new BufferedReader(new InputStreamReader(
     121                    new FileInputStream(_file), "UTF-8"));
    123122            String line = null;
    124123            while ( (line = br.readLine()) != null) {
     
    142141        } catch (IOException ioe) {
    143142        } finally {
    144             if (in != null) try { in.close(); } catch (IOException ioe) {}
     143            if (br != null) try { br.close(); } catch (IOException ioe) {}
    145144        }
    146145        return rv;
Note: See TracChangeset for help on using the changeset viewer.