- Timestamp:
- 2016-01-03T16:30:55+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java
r9187 r9280 7 7 import java.awt.event.ActionEvent; 8 8 import java.io.File; 9 import java.io.FileOutputStream;10 9 import java.io.IOException; 11 10 import java.io.InputStream; 12 11 import java.net.URI; 12 import java.nio.file.Files; 13 import java.nio.file.StandardCopyOption; 13 14 import java.util.Arrays; 14 15 import java.util.List; … … 153 154 file = File.createTempFile("session_", ".joz", Utils.getJosmTempDir()); 154 155 tempFile = true; 155 try (FileOutputStream out = new FileOutputStream(file)) { 156 Utils.copyStream(is, out); 157 } 156 Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); 158 157 } 159 158 reader.loadSession(file, zip, monitor); -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r9078 r9280 16 16 import java.awt.event.MouseEvent; 17 17 import java.io.BufferedInputStream; 18 import java.io.BufferedOutputStream;19 18 import java.io.BufferedReader; 20 19 import java.io.File; 21 import java.io.FileOutputStream;22 20 import java.io.IOException; 23 21 import java.io.InputStream; 24 22 import java.io.InputStreamReader; 25 import java.io.OutputStream;26 23 import java.nio.charset.StandardCharsets; 24 import java.nio.file.Files; 25 import java.nio.file.StandardCopyOption; 27 26 import java.util.ArrayList; 28 27 import java.util.Arrays; … … 510 509 try { 511 510 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); 521 513 } finally { 522 514 s.closeSourceInputStream(in); 523 515 } 524 516 } catch (IOException e) { 517 Main.warn(e); 525 518 error = true; 526 519 } -
trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
r9171 r9280 5 5 6 6 import java.awt.Component; 7 import java.io.BufferedOutputStream;8 7 import java.io.File; 9 8 import java.io.FileOutputStream; … … 14 13 import java.net.URL; 15 14 import java.nio.charset.StandardCharsets; 15 import java.nio.file.Files; 16 import java.nio.file.StandardCopyOption; 16 17 import java.util.Enumeration; 17 18 import java.util.zip.ZipEntry; … … 182 183 if (ze.isDirectory()) { 183 184 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); 193 187 } 194 188 } -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r9168 r9280 5 5 6 6 import java.io.BufferedInputStream; 7 import java.io.BufferedOutputStream;8 7 import java.io.File; 9 8 import java.io.FileInputStream; 10 import java.io.FileOutputStream;11 9 import java.io.IOException; 12 10 import java.io.InputStream; 13 import java.io.OutputStream;14 11 import java.net.HttpURLConnection; 15 12 import java.net.MalformedURLException; 16 13 import java.net.URL; 17 14 import java.nio.charset.StandardCharsets; 15 import java.nio.file.Files; 16 import java.nio.file.StandardCopyOption; 18 17 import java.util.ArrayList; 19 18 import java.util.Arrays; … … 429 428 return localFile; 430 429 } 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); 441 432 } 442 433 localFile = new File(destDir, localPath); -
trunk/src/org/openstreetmap/josm/plugins/Plugin.java
r9231 r9280 4 4 import java.io.File; 5 5 import java.io.FileNotFoundException; 6 import java.io.FileOutputStream;7 6 import java.io.IOException; 8 7 import java.io.InputStream; 9 8 import java.net.URL; 10 9 import java.net.URLClassLoader; 10 import java.nio.file.Files; 11 import java.nio.file.StandardCopyOption; 11 12 import java.security.AccessController; 12 13 import java.security.PrivilegedAction; … … 119 120 pluginDir.mkdirs(); 120 121 } 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)) { 125 123 if (in == null) { 126 124 throw new IOException("Resource not found: "+from); 127 125 } 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); 132 127 } 133 128 } -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r9168 r9280 6 6 import java.awt.Component; 7 7 import java.io.File; 8 import java.io.FileOutputStream;9 8 import java.io.IOException; 10 9 import java.io.InputStream; 11 import java.io.OutputStream;12 10 import java.net.MalformedURLException; 13 11 import java.net.URL; 12 import java.nio.file.Files; 13 import java.nio.file.StandardCopyOption; 14 14 import java.util.Collection; 15 15 import java.util.LinkedList; … … 127 127 .connect(); 128 128 } 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); 137 131 } 138 132 } catch (MalformedURLException e) { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r9274 r9280 23 23 import java.io.InputStream; 24 24 import java.io.InputStreamReader; 25 import java.io.OutputStream;26 25 import java.io.UnsupportedEncodingException; 27 26 import java.net.HttpURLConnection; … … 435 434 436 435 /** 437 * Copy data from source stream to output stream.438 * @param source source stream439 * @param destination target stream440 * @return number of bytes copied441 * @throws IOException if any I/O error occurs442 */443 public static int copyStream(InputStream source, OutputStream destination) throws IOException {444 int count = 0;445 byte[] b = new byte[512];446 int read;447 while ((read = source.read(b)) != -1) {448 count += read;449 destination.write(b, 0, read);450 }451 return count;452 }453 454 /**455 436 * Deletes a directory recursively. 456 437 * @param path The directory to delete
Note:
See TracChangeset
for help on using the changeset viewer.