Changeset 13204 in josm
- Timestamp:
- 2017-12-17T00:17:20+01:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r12856 r13204 3 3 4 4 import java.io.File; 5 import java.io.FileOutputStream;6 5 import java.io.IOException; 6 import java.nio.channels.FileChannel; 7 7 import java.nio.channels.FileLock; 8 import java.nio.file.StandardOpenOption; 8 9 import java.util.Arrays; 9 10 import java.util.Properties; … … 110 111 Logging.warn("Cannot create cache dir lock file"); 111 112 } 112 cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock();113 cacheDirLock = FileChannel.open(cacheDirLockPath.toPath(), StandardOpenOption.WRITE).tryLock(); 113 114 114 115 if (cacheDirLock == null) -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2Proj4DirGridShiftFileSource.java
r12868 r13204 3 3 4 4 import java.io.File; 5 import java.io.FileInputStream; 6 import java.io.FileNotFoundException; 5 import java.io.IOException; 7 6 import java.io.InputStream; 7 import java.nio.file.Files; 8 import java.nio.file.InvalidPathException; 8 9 import java.util.Arrays; 9 10 import java.util.Collections; … … 63 64 if (grid != null) { 64 65 try { 65 return new FileInputStream(grid.getAbsoluteFile());66 } catch ( FileNotFoundException ex) {67 Logging.warn(" NTV2 grid shift file not found: " + grid);68 Logging. trace(ex);66 return Files.newInputStream(grid.getAbsoluteFile().toPath()); 67 } catch (IOException | InvalidPathException ex) { 68 Logging.warn("Unable to open NTV2 grid shift file: " + grid); 69 Logging.debug(ex); 69 70 } 70 71 } -
trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java
r13173 r13204 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.BufferedInputStream;7 6 import java.io.ByteArrayInputStream; 8 7 import java.io.CharArrayReader; 9 8 import java.io.CharArrayWriter; 10 9 import java.io.File; 11 import java.io.FileInputStream;12 10 import java.io.IOException; 13 11 import java.io.InputStream; 14 12 import java.nio.charset.StandardCharsets; 13 import java.nio.file.Files; 14 import java.nio.file.InvalidPathException; 15 15 import java.util.ArrayList; 16 16 import java.util.Collection; … … 397 397 String fileDir = file.getParentFile().getAbsolutePath(); 398 398 if (fileDir != null) engine.eval("scriptDir='"+normalizeDirName(fileDir) +"';"); 399 try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {399 try (InputStream is = Files.newInputStream(file.toPath())) { 400 400 openAndReadXML(is); 401 401 } 402 } catch (ScriptException | IOException | SecurityException ex) {402 } catch (ScriptException | IOException | SecurityException | InvalidPathException ex) { 403 403 PreferencesUtils.log(ex, "Error reading custom preferences:"); 404 404 } -
trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java
r12620 r13204 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; … … 14 13 import java.nio.charset.StandardCharsets; 15 14 import java.nio.file.Files; 15 import java.nio.file.InvalidPathException; 16 16 import java.nio.file.StandardCopyOption; 17 17 import java.util.Enumeration; … … 115 115 try ( 116 116 InputStream in = downloadConnection.getResponse().getContent(); 117 OutputStream out = new FileOutputStream(file)117 OutputStream out = Files.newOutputStream(file.toPath()) 118 118 ) { 119 119 byte[] buffer = new byte[32_768]; … … 145 145 Logging.warn(msg); 146 146 throw new DownloadException(msg, e); 147 } catch (IOException e) {147 } catch (IOException | InvalidPathException e) { 148 148 if (canceled) 149 149 return; -
trunk/src/org/openstreetmap/josm/gui/io/importexport/NoteExporter.java
r12671 r13204 5 5 6 6 import java.io.File; 7 import java.io.FileOutputStream;8 7 import java.io.IOException; 9 8 import java.io.OutputStream; 9 import java.nio.file.Files; 10 10 11 11 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 40 40 Logging.info("exporting notes to file: " + file); 41 41 if (layer instanceof NoteLayer) { 42 try (OutputStream os = new FileOutputStream(file);42 try (OutputStream os = Files.newOutputStream(file.toPath()); 43 43 NoteWriter writer = new NoteWriter(os)) { 44 44 writer.write(((NoteLayer) layer).getNoteData()); -
trunk/src/org/openstreetmap/josm/gui/io/importexport/ValidatorErrorExporter.java
r12671 r13204 5 5 6 6 import java.io.File; 7 import java.io.FileOutputStream;8 7 import java.io.IOException; 9 8 import java.io.OutputStream; 9 import java.nio.file.Files; 10 10 11 11 import org.openstreetmap.josm.actions.ExtensionFileFilter; … … 44 44 if (layer instanceof ValidatorLayer && editLayer != null) { 45 45 Logging.info("exporting validation errors to file: " + file); 46 try (OutputStream os = new FileOutputStream(file);46 try (OutputStream os = Files.newOutputStream(file.toPath()); 47 47 ValidatorErrorWriter writer = new ValidatorErrorWriter(os)) { 48 48 writer.write(editLayer.validationErrors); -
trunk/src/org/openstreetmap/josm/gui/io/importexport/WMSLayerExporter.java
r12851 r13204 3 3 4 4 import java.io.File; 5 import java.io.FileOutputStream;6 5 import java.io.IOException; 7 6 import java.io.ObjectOutputStream; 7 import java.nio.file.Files; 8 8 9 9 import org.openstreetmap.josm.data.StructUtils; … … 38 38 39 39 if (layer instanceof AbstractTileSourceLayer) { 40 try (ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream(file))) {40 try (ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(file.toPath()))) { 41 41 oos.writeInt(CURRENT_FILE_VERSION); // file version 42 42 oos.writeObject(MainApplication.getMap().mapView.getCenter()); 43 ImageryPreferenceEntry entry = new ImageryPreferenceEntry(((AbstractTileSourceLayer ) layer).getInfo());43 ImageryPreferenceEntry entry = new ImageryPreferenceEntry(((AbstractTileSourceLayer<?>) layer).getInfo()); 44 44 oos.writeObject(StructUtils.serializeStruct(entry, ImageryPreferenceEntry.class)); 45 45 } -
trunk/src/org/openstreetmap/josm/gui/io/importexport/WMSLayerImporter.java
r12851 r13204 5 5 6 6 import java.io.File; 7 import java.io.FileInputStream;8 7 import java.io.IOException; 9 8 import java.io.InvalidClassException; 10 9 import java.io.ObjectInputStream; 10 import java.nio.file.Files; 11 11 import java.util.Map; 12 12 … … 49 49 final ImageryLayer layer; 50 50 51 try (ObjectInputStream ois = new ObjectInputStream( new FileInputStream(file))) {51 try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file.toPath()))) { 52 52 int sfv = ois.readInt(); 53 53 if (sfv < 5) { -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r13130 r13204 21 21 import java.awt.event.WindowEvent; 22 22 import java.io.File; 23 import java.io.FileInputStream;24 23 import java.io.IOException; 25 24 import java.io.InputStream; 25 import java.nio.file.Files; 26 26 import java.text.DateFormat; 27 27 import java.text.ParseException; … … 331 331 private InputStream createInputStream(File sel) throws IOException { 332 332 if (Utils.hasExtension(sel, "gpx.gz")) { 333 return new GZIPInputStream( new FileInputStream(sel));333 return new GZIPInputStream(Files.newInputStream(sel.toPath())); 334 334 } else { 335 return new FileInputStream(sel);335 return Files.newInputStream(sel.toPath()); 336 336 } 337 337 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java
r13050 r13204 7 7 import java.awt.image.BufferedImage; 8 8 import java.io.File; 9 import java.io.FileInputStream;10 9 import java.io.FileNotFoundException; 11 10 import java.io.IOException; 11 import java.nio.file.Files; 12 import java.nio.file.Paths; 12 13 import java.util.ArrayList; 13 14 import java.util.List; … … 543 544 } 544 545 545 private DataSet loadDataset() throws FileNotFoundException, IllegalDataException {546 private DataSet loadDataset() throws IOException, IllegalDataException { 546 547 if (argInput == null) { 547 548 throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i")); 548 549 } 549 550 try { 550 return OsmReader.parseDataSet( new FileInputStream(argInput), null);551 return OsmReader.parseDataSet(Files.newInputStream(Paths.get(argInput)), null); 551 552 } catch (IllegalDataException e) { 552 553 throw new IllegalDataException(tr("In .osm data file ''{0}'' - ", argInput) + e.getMessage()); -
trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java
r12856 r13204 5 5 import java.io.BufferedOutputStream; 6 6 import java.io.File; 7 import java.io.FileInputStream;8 import java.io.FileOutputStream;9 7 import java.io.IOException; 10 8 import java.nio.charset.StandardCharsets; 9 import java.nio.file.Files; 10 import java.nio.file.InvalidPathException; 11 11 import java.util.concurrent.TimeUnit; 12 12 … … 185 185 */ 186 186 private void loadFromDisk() throws T { 187 try (BufferedInputStream input = new BufferedInputStream( new FileInputStream(path))) {187 try (BufferedInputStream input = new BufferedInputStream(Files.newInputStream(path.toPath()))) { 188 188 this.data = new byte[input.available()]; 189 189 if (input.read(this.data) < this.data.length) { 190 190 Logging.error("Failed to read expected contents from "+path); 191 191 } 192 } catch (IOException e) {192 } catch (IOException | InvalidPathException e) { 193 193 Logging.trace(e); 194 194 if (!isOffline()) { … … 202 202 */ 203 203 private void saveToDisk() { 204 try (BufferedOutputStream output = new BufferedOutputStream( new FileOutputStream(path))) {204 try (BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(path.toPath()))) { 205 205 output.write(this.data); 206 206 output.flush(); 207 } catch (IOException e) {207 } catch (IOException | InvalidPathException e) { 208 208 Logging.error(e); 209 209 } -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r12856 r13204 8 8 import java.io.Closeable; 9 9 import java.io.File; 10 import java.io.FileInputStream;11 10 import java.io.IOException; 12 11 import java.io.InputStream; … … 218 217 } 219 218 } 220 return new FileInputStream(file);219 return Files.newInputStream(file.toPath()); 221 220 } 222 221 -
trunk/src/org/openstreetmap/josm/io/Compression.java
r12772 r13204 3 3 4 4 import java.io.File; 5 import java.io.FileInputStream;6 import java.io.FileOutputStream;7 5 import java.io.IOException; 8 6 import java.io.InputStream; 9 7 import java.io.OutputStream; 10 8 import java.nio.charset.StandardCharsets; 9 import java.nio.file.Files; 11 10 import java.util.zip.GZIPInputStream; 12 11 import java.util.zip.GZIPOutputStream; … … 150 149 */ 151 150 public static InputStream getUncompressedFileInputStream(File file) throws IOException { 152 FileInputStream in = new FileInputStream(file);151 InputStream in = Files.newInputStream(file.toPath()); 153 152 try { 154 153 return byExtension(file.getName()).getUncompressedInputStream(in); … … 188 187 */ 189 188 public static OutputStream getCompressedFileOutputStream(File file) throws IOException { 190 FileOutputStream out = new FileOutputStream(file);189 OutputStream out = Files.newOutputStream(file.toPath()); 191 190 try { 192 191 return byExtension(file.getName()).getCompressedOutputStream(out); -
trunk/src/org/openstreetmap/josm/io/session/SessionReader.java
r12620 r13204 7 7 import java.io.BufferedInputStream; 8 8 import java.io.File; 9 import java.io.FileInputStream;10 9 import java.io.FileNotFoundException; 11 10 import java.io.IOException; … … 15 14 import java.net.URISyntaxException; 16 15 import java.nio.charset.StandardCharsets; 16 import java.nio.file.Files; 17 17 import java.util.ArrayList; 18 18 import java.util.Collection; … … 715 715 } 716 716 } else { 717 try { 718 return new FileInputStream(sessionFile); 719 } catch (FileNotFoundException ex) { 720 throw new IOException(ex); 721 } 717 return Files.newInputStream(sessionFile.toPath()); 722 718 } 723 719 } -
trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java
r12778 r13204 4 4 import java.io.BufferedOutputStream; 5 5 import java.io.File; 6 import java.io.FileNotFoundException;7 import java.io.FileOutputStream;8 6 import java.io.IOException; 9 7 import java.io.OutputStream; 10 8 import java.io.OutputStreamWriter; 11 9 import java.nio.charset.StandardCharsets; 10 import java.nio.file.Files; 12 11 import java.util.ArrayList; 13 12 import java.util.Collection; … … 331 330 */ 332 331 public void write(File f) throws IOException { 333 try (OutputStream out = new FileOutputStream(f)) {332 try (OutputStream out = Files.newOutputStream(f.toPath())) { 334 333 write(out); 335 } catch (FileNotFoundException e) {336 throw new IOException(e);337 334 } 338 335 } -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r12620 r13204 5 5 6 6 import java.io.File; 7 import java.io.FileInputStream;8 7 import java.io.IOException; 9 8 import java.io.InputStream; 10 9 import java.lang.reflect.Constructor; 11 10 import java.net.URL; 11 import java.nio.file.Files; 12 import java.nio.file.InvalidPathException; 12 13 import java.text.MessageFormat; 13 14 import java.util.ArrayList; … … 114 115 this.file = file; 115 116 try ( 116 FileInputStream fis = new FileInputStream(file);117 InputStream fis = Files.newInputStream(file.toPath()); 117 118 JarInputStream jar = new JarInputStream(fis) 118 119 ) { … … 122 123 scanManifest(manifest, false); 123 124 libraries.add(0, Utils.fileToURL(file)); 124 } catch (IOException e) {125 } catch (IOException | InvalidPathException e) { 125 126 throw new PluginException(name, e); 126 127 } -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r12620 r13204 5 5 6 6 import java.io.File; 7 import java.io.FileInputStream;8 7 import java.io.FilenameFilter; 9 8 import java.io.IOException; 9 import java.io.InputStream; 10 import java.nio.file.Files; 11 import java.nio.file.InvalidPathException; 10 12 import java.util.ArrayList; 11 13 import java.util.Collection; … … 145 147 146 148 protected void processLocalPluginInformationFile(File file) throws PluginListParseException { 147 try ( FileInputStream fin = new FileInputStream(file)) {149 try (InputStream fin = Files.newInputStream(file.toPath())) { 148 150 List<PluginInformation> pis = new PluginListParser().parse(fin); 149 151 for (PluginInformation pi : pis) { … … 154 156 availablePlugins.put(pi.name, pi); 155 157 } 156 } catch (IOException e) {158 } catch (IOException | InvalidPathException e) { 157 159 throw new PluginListParseException(e); 158 160 } -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r12931 r13204 4 4 import java.io.BufferedInputStream; 5 5 import java.io.File; 6 import java.io.FileInputStream;7 6 import java.io.IOException; 8 7 import java.io.InputStream; … … 11 10 import java.net.URL; 12 11 import java.nio.charset.StandardCharsets; 12 import java.nio.file.Files; 13 import java.nio.file.InvalidPathException; 13 14 import java.text.MessageFormat; 14 15 import java.util.ArrayList; … … 372 373 final String langfile = "data/"+loadedCode+".lang"; 373 374 try ( 374 FileInputStream fis = new FileInputStream(source);375 InputStream fis = Files.newInputStream(source.toPath()); 375 376 JarInputStream jar = new JarInputStream(fis) 376 377 ) { … … 384 385 if (found) { 385 386 try ( 386 FileInputStream fisTrans = new FileInputStream(source);387 InputStream fisTrans = Files.newInputStream(source.toPath()); 387 388 JarInputStream jarTrans = new JarInputStream(fisTrans) 388 389 ) { … … 397 398 } 398 399 } 399 } catch (IOException e) { 400 // Ignore 400 } catch (IOException | InvalidPathException e) { 401 401 Logging.trace(e); 402 402 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r12846 r13204 8 8 import java.io.BufferedReader; 9 9 import java.io.File; 10 import java.io.FileInputStream;11 10 import java.io.IOException; 11 import java.io.InputStream; 12 12 import java.net.URI; 13 13 import java.net.URISyntaxException; … … 403 403 if (f.exists()) { 404 404 CertificateFactory fact = CertificateFactory.getInstance("X.509"); 405 try ( FileInputStream is = new FileInputStream(f)) {405 try (InputStream is = Files.newInputStream(f.toPath())) { 406 406 return (X509Certificate) fact.generateCertificate(is); 407 407 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r12887 r13204 32 32 import java.io.BufferedWriter; 33 33 import java.io.File; 34 import java.io.FileInputStream;35 34 import java.io.IOException; 35 import java.io.InputStream; 36 36 import java.io.OutputStream; 37 37 import java.io.OutputStreamWriter; … … 42 42 import java.nio.file.FileSystems; 43 43 import java.nio.file.Files; 44 import java.nio.file.InvalidPathException; 44 45 import java.nio.file.Path; 45 46 import java.security.InvalidKeyException; … … 518 519 return; 519 520 } 520 try ( FileInputStream fis = new FileInputStream(templateFile.toFile())) {521 try (InputStream fis = Files.newInputStream(templateFile)) { 521 522 Properties props = new Properties(); 522 523 props.load(fis); … … 581 582 } 582 583 Utils.updateSystemProperty("sun.awt.fontconfig", fontconfigFile.toString()); 583 } catch (IOException ex) {584 } catch (IOException | InvalidPathException ex) { 584 585 Logging.error(ex); 585 586 } -
trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
r12856 r13204 3 3 4 4 import java.io.File; 5 import java.io.FileInputStream;6 import java.io.FileOutputStream;7 5 import java.io.IOException; 8 6 import java.io.InputStream; … … 11 9 import java.io.Writer; 12 10 import java.nio.charset.StandardCharsets; 11 import java.nio.file.Files; 12 import java.nio.file.InvalidPathException; 13 import java.nio.file.Paths; 13 14 import java.util.ArrayList; 14 15 import java.util.Collection; … … 154 155 DataSet ds = optimizedWays.iterator().next().getDataSet(); 155 156 File file = new File(Config.getDirs().getCacheDirectory(true), "left-right-hand-traffic.osm"); 156 try (Writer writer = new OutputStreamWriter( new FileOutputStream(file), StandardCharsets.UTF_8);157 try (Writer writer = new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8); 157 158 OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion()) 158 159 ) { … … 166 167 167 168 private static Collection<Way> loadOptimizedBoundaries() { 168 try (InputStream is = new FileInputStream(new File(169 Config.getDirs().getCacheDirectory(false) , "left-right-hand-traffic.osm"))) {169 try (InputStream is = Files.newInputStream(Paths.get( 170 Config.getDirs().getCacheDirectory(false).getPath(), "left-right-hand-traffic.osm"))) { 170 171 return OsmReader.parseDataSet(is, null).getWays(); 171 } catch (IllegalDataException | IOException ex) {172 } catch (IllegalDataException | IOException | InvalidPathException ex) { 172 173 Logging.trace(ex); 173 174 return Collections.emptyList(); -
trunk/tools/pmd/josm-ruleset.xml
r13202 r13204 170 170 </rule> 171 171 <rule ref="category/java/performance.xml"> 172 <exclude name="AvoidFileStream"/>173 172 <exclude name="AvoidInstantiatingObjectsInLoops"/> 174 173 <exclude name="AvoidUsingShortType"/>
Note:
See TracChangeset
for help on using the changeset viewer.