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/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r9078 r9280  
    1616import java.awt.event.MouseEvent;
    1717import java.io.BufferedInputStream;
    18 import java.io.BufferedOutputStream;
    1918import java.io.BufferedReader;
    2019import java.io.File;
    21 import java.io.FileOutputStream;
    2220import java.io.IOException;
    2321import java.io.InputStream;
    2422import java.io.InputStreamReader;
    25 import java.io.OutputStream;
    2623import java.nio.charset.StandardCharsets;
     24import java.nio.file.Files;
     25import java.nio.file.StandardCopyOption;
    2726import java.util.ArrayList;
    2827import java.util.Arrays;
     
    510509                try {
    511510                    InputStream in = s.getSourceInputStream();
    512                     try (
    513                         InputStream bis = new BufferedInputStream(in);
    514                         OutputStream bos = new BufferedOutputStream(new FileOutputStream(file))
    515                     ) {
    516                         byte[] buffer = new byte[4096];
    517                         int length;
    518                         while ((length = bis.read(buffer)) > -1 && !canceled) {
    519                             bos.write(buffer, 0, length);
    520                         }
     511                    try (InputStream bis = new BufferedInputStream(in)) {
     512                        Files.copy(bis, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
    521513                    } finally {
    522514                        s.closeSourceInputStream(in);
    523515                    }
    524516                } catch (IOException e) {
     517                    Main.warn(e);
    525518                    error = true;
    526519                }
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java

    r9171 r9280  
    55
    66import java.awt.Component;
    7 import java.io.BufferedOutputStream;
    87import java.io.File;
    98import java.io.FileOutputStream;
     
    1413import java.net.URL;
    1514import java.nio.charset.StandardCharsets;
     15import java.nio.file.Files;
     16import java.nio.file.StandardCopyOption;
    1617import java.util.Enumeration;
    1718import java.util.zip.ZipEntry;
     
    182183                if (ze.isDirectory()) {
    183184                    newFile.mkdirs();
    184                 } else try (
    185                     InputStream is = zf.getInputStream(ze);
    186                     OutputStream os = new BufferedOutputStream(new FileOutputStream(newFile))
    187                 ) {
    188                     byte[] buffer = new byte[8192];
    189                     int read;
    190                     while ((read = is.read(buffer)) != -1) {
    191                         os.write(buffer, 0, read);
    192                     }
     185                } else try (InputStream is = zf.getInputStream(ze)) {
     186                    Files.copy(is, newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    193187                }
    194188            }
Note: See TracChangeset for help on using the changeset viewer.