Ignore:
Timestamp:
2016-01-03T16:30:55+01:00 (8 years ago)
Author:
Don-vip
Message:

improve performance and simplify file copy operations (major performance gain when downloading geotools plugin)

Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
2 edited

Legend:

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

    r9231 r9280  
    44import java.io.File;
    55import java.io.FileNotFoundException;
    6 import java.io.FileOutputStream;
    76import java.io.IOException;
    87import java.io.InputStream;
    98import java.net.URL;
    109import java.net.URLClassLoader;
     10import java.nio.file.Files;
     11import java.nio.file.StandardCopyOption;
    1112import java.security.AccessController;
    1213import java.security.PrivilegedAction;
     
    119120            pluginDir.mkdirs();
    120121        }
    121         try (
    122             FileOutputStream out = new FileOutputStream(new File(pluginDirName, to));
    123             InputStream in = getClass().getResourceAsStream(from)
    124         ) {
     122        try (InputStream in = getClass().getResourceAsStream(from)) {
    125123            if (in == null) {
    126124                throw new IOException("Resource not found: "+from);
    127125            }
    128             byte[] buffer = new byte[8192];
    129             for (int len = in.read(buffer); len > 0; len = in.read(buffer)) {
    130                 out.write(buffer, 0, len);
    131             }
     126            Files.copy(in, new File(pluginDirName, to).toPath(), StandardCopyOption.REPLACE_EXISTING);
    132127        }
    133128    }
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java

    r9168 r9280  
    66import java.awt.Component;
    77import java.io.File;
    8 import java.io.FileOutputStream;
    98import java.io.IOException;
    109import java.io.InputStream;
    11 import java.io.OutputStream;
    1210import java.net.MalformedURLException;
    1311import java.net.URL;
     12import java.nio.file.Files;
     13import java.nio.file.StandardCopyOption;
    1414import java.util.Collection;
    1515import java.util.LinkedList;
     
    127127                        .connect();
    128128            }
    129             try (
    130                 InputStream in = downloadConnection.getContent();
    131                 OutputStream out = new FileOutputStream(file)
    132             ) {
    133                 byte[] buffer = new byte[8192];
    134                 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) {
    135                     out.write(buffer, 0, read);
    136                 }
     129            try (InputStream in = downloadConnection.getContent()) {
     130                Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
    137131            }
    138132        } catch (MalformedURLException e) {
Note: See TracChangeset for help on using the changeset viewer.