Changeset a67ea4b for core


Ignore:
Timestamp:
Dec 9, 2017 1:02:17 AM (3 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.

Location:
core/java/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/freenet/support/CPUInformation/CPUID.java

    rfe5e4a2 ra67ea4b  
    552552        if (resource == null)
    553553            return false;
     554        InputStream libStream = null;
    554555        File outFile = null;
    555556        FileOutputStream fos = null;
    556557        String filename = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
    557558        try {
    558             InputStream libStream = resource.openStream();
     559            libStream = resource.openStream();
    559560            outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename);
    560561            fos = new FileOutputStream(outFile);
     
    581582            return false;
    582583        } finally {
     584            if (libStream != null) try { libStream.close(); } catch (IOException ioe) {}
    583585            if (fos != null) {
    584586                try { fos.close(); } catch (IOException ioe) {}
  • core/java/src/net/i2p/client/naming/SingleFileNamingService.java

    rfe5e4a2 ra67ea4b  
    211211            return success;
    212212        } catch (IOException ioe) {
     213            _log.error("Error adding " + hostname, ioe);
     214            return false;
     215        } finally {
    213216            if (in != null) try { in.close(); } catch (IOException e) {}
    214217            if (out != null) try { out.close(); } catch (IOException e) {}
    215             _log.error("Error adding " + hostname, ioe);
    216             return false;
    217         } finally { releaseWriteLock(); }
     218            releaseWriteLock();
     219        }
    218220    }
    219221
     
    334336            return success;
    335337        } catch (IOException ioe) {
     338            _log.error("Error removing " + hostname, ioe);
     339            return false;
     340        } finally {
    336341            if (in != null) try { in.close(); } catch (IOException e) {}
    337342            if (out != null) try { out.close(); } catch (IOException e) {}
    338             _log.error("Error removing " + hostname, ioe);
    339             return false;
    340         } finally {
    341343            releaseWriteLock();
    342344        }
  • core/java/src/net/i2p/crypto/TrustedUpdate.java

    rfe5e4a2 ra67ea4b  
    765765            return null;
    766766        } finally {
    767             if (bytesToSignInputStream != null)
    768                 try {
    769                     bytesToSignInputStream.close();
    770                     fileInputStream.close();
    771                 } catch (IOException ioe) {
    772                 }
    773 
     767            if (bytesToSignInputStream != null) try { bytesToSignInputStream.close(); } catch (IOException ioe) {}
     768            if (fileInputStream != null) try { fileInputStream.close(); } catch (IOException ioe) {}
    774769        }
    775770
  • core/java/src/net/i2p/data/DataHelper.java

    rfe5e4a2 ra67ea4b  
    495495     */
    496496    public static void storeProps(Properties props, File file) throws IOException {
     497        FileOutputStream fos = null;
    497498        PrintWriter out = null;
    498499        IllegalArgumentException iae = null;
    499500        File tmpFile = new File(file.getPath() + ".tmp");
    500501        try {
    501             FileOutputStream fos = new SecureFileOutputStream(tmpFile);
     502            fos = new SecureFileOutputStream(tmpFile);
    502503            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")));
    503504            out.println("# NOTE: This I2P config file must use UTF-8 encoding");
     
    534535        } finally {
    535536            if (out != null) out.close();
     537            if (fos != null) try { fos.close(); } catch (IOException ioe) {}
    536538        }
    537539        if (iae != null)
  • core/java/src/net/i2p/util/NativeBigInteger.java

    rfe5e4a2 ra67ea4b  
    11201120        }
    11211121
     1122        InputStream libStream = null;
    11221123        File outFile = null;
    11231124        FileOutputStream fos = null;
    11241125        String filename =  _libPrefix + "jbigi" + _libSuffix;
    11251126        try {
    1126             InputStream libStream = resource.openStream();
     1127            libStream = resource.openStream();
    11271128            outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename);
    11281129            fos = new FileOutputStream(outFile);
     
    11441145            return false;
    11451146        } finally {
     1147            if (libStream != null) try { libStream.close(); } catch (IOException ioe) {}
    11461148            if (fos != null) {
    11471149                try { fos.close(); } catch (IOException ioe) {}
  • core/java/src/net/i2p/util/TranslateReader.java

    rfe5e4a2 ra67ea4b  
    396396    private static void test(String file) throws IOException {
    397397        FileInputStream fio = new FileInputStream(file);
    398         TranslateReader r = new TranslateReader(I2PAppContext.getGlobalContext(),
    399                                                 "net.i2p.router.web.messages",
    400                                                 fio);
    401         int c;
    402         while ((c = r.read()) >= 0) {
    403             System.out.print((char)c);
    404         }
    405         System.out.flush();
    406         r.close();
     398        TranslateReader r = null;
     399        try {
     400            r = new TranslateReader(I2PAppContext.getGlobalContext(),
     401                                    "net.i2p.router.web.messages",
     402                                    fio);
     403            int c;
     404            while ((c = r.read()) >= 0) {
     405                System.out.print((char)c);
     406            }
     407            System.out.flush();
     408        } finally {
     409            if (r != null) try { r.close(); } catch (IOException ioe) {}
     410        }
    407411    }
    408412
Note: See TracChangeset for help on using the changeset viewer.