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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r9168 r9280  
    55
    66import java.io.BufferedInputStream;
    7 import java.io.BufferedOutputStream;
    87import java.io.File;
    98import java.io.FileInputStream;
    10 import java.io.FileOutputStream;
    119import java.io.IOException;
    1210import java.io.InputStream;
    13 import java.io.OutputStream;
    1411import java.net.HttpURLConnection;
    1512import java.net.MalformedURLException;
    1613import java.net.URL;
    1714import java.nio.charset.StandardCharsets;
     15import java.nio.file.Files;
     16import java.nio.file.StandardCopyOption;
    1817import java.util.ArrayList;
    1918import java.util.Arrays;
     
    429428                return localFile;
    430429            }
    431             try (
    432                 InputStream bis = new BufferedInputStream(con.getContent());
    433                 OutputStream fos = new FileOutputStream(destDirFile);
    434                 OutputStream bos = new BufferedOutputStream(fos)
    435             ) {
    436                 byte[] buffer = new byte[4096];
    437                 int length;
    438                 while ((length = bis.read(buffer)) > -1) {
    439                     bos.write(buffer, 0, length);
    440                 }
     430            try (InputStream bis = new BufferedInputStream(con.getContent())) {
     431                Files.copy(bis, destDirFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    441432            }
    442433            localFile = new File(destDir, localPath);
Note: See TracChangeset for help on using the changeset viewer.