Ignore:
Timestamp:
2013-04-16T19:57:43+02:00 (10 years ago)
Author:
Don-vip
Message:

see #8570, #7406 - I/O refactorization:

  • Move different file copy functions to Utils.copyFile (to be replaced later by Files.copy when switching to Java 7)
  • Replace all Utils.close(XXX) by Utils.close(Closeable) -> impacted plugins: commandline, mirrored_download, opendata, piclayer
  • Add new Utils.close(ZipFile)
  • Use of Utils.close almost everywhere
  • Javadoc fixes
Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r5836 r5874  
    1515import org.openstreetmap.josm.gui.download.DownloadSelection;
    1616import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
     17import org.openstreetmap.josm.tools.Utils;
    1718
    1819/**
     
    110111            pluginDir.mkdirs();
    111112        }
    112         FileOutputStream out = new FileOutputStream(new File(pluginDirName, to));
    113         InputStream in = getClass().getResourceAsStream(from);
    114         byte[] buffer = new byte[8192];
    115         for(int len = in.read(buffer); len > 0; len = in.read(buffer)) {
    116             out.write(buffer, 0, len);
     113        FileOutputStream out = null;
     114        InputStream in = null;
     115        try {
     116            out = new FileOutputStream(new File(pluginDirName, to));
     117            in = getClass().getResourceAsStream(from);
     118            byte[] buffer = new byte[8192];
     119            for(int len = in.read(buffer); len > 0; len = in.read(buffer)) {
     120                out.write(buffer, 0, len);
     121            }
     122        } finally {
     123            Utils.close(in);
     124            Utils.close(out);
    117125        }
    118         in.close();
    119         out.close();
    120126    }
    121127
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java

    r5836 r5874  
    129129                out.write(buffer, 0, read);
    130130            }
    131             out.close();
    132             in.close();
    133131        } catch(MalformedURLException e) {
    134132            String msg = tr("Warning: Cannot download plugin ''{0}''. Its download link ''{1}'' is not a valid URL. Skipping download.", pi.name, pi.downloadlink);
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r5836 r5874  
    2929import org.openstreetmap.josm.tools.ImageProvider;
    3030import org.openstreetmap.josm.tools.LanguageInfo;
     31import org.openstreetmap.josm.tools.Utils;
    3132
    3233/**
     
    100101            throw new PluginException(name, e);
    101102        } finally {
    102             if (jar != null) {
    103                 try {
    104                     jar.close();
    105                 } catch(IOException e) { /* ignore */ }
    106             }
    107             if (fis != null) {
    108                 try {
    109                     fis.close();
    110                 } catch(IOException e) { /* ignore */ }
    111             }
     103            Utils.close(jar);
     104            Utils.close(fis);
    112105        }
    113106    }
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r5836 r5874  
    218218                out.write(buffer, 0, read);
    219219            }
    220             out.close();
    221             in.close();
    222220        } catch(MalformedURLException e) {
    223221            if (canceled) return;
     
    229227            return;
    230228        } finally {
     229            Utils.close(out);
    231230            synchronized(this) {
    232231                if (connection != null) {
     
    274273            if (writer != null) {
    275274                writer.flush();
    276                 writer.close();
     275                Utils.close(writer);
    277276            }
    278277        }
Note: See TracChangeset for help on using the changeset viewer.