Ignore:
Timestamp:
2017-12-17T00:17:20+01:00 (2 years ago)
Author:
Don-vip
Message:

enable new PMD rule AvoidFileStream - see https://pmd.github.io/pmd-6.0.0/pmd_rules_java_performance.html#avoidfilestream / https://bugs.openjdk.java.net/browse/JDK-8080225 for details

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
8 edited

Legend:

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

    r13173 r13204  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.io.BufferedInputStream;
    76import java.io.ByteArrayInputStream;
    87import java.io.CharArrayReader;
    98import java.io.CharArrayWriter;
    109import java.io.File;
    11 import java.io.FileInputStream;
    1210import java.io.IOException;
    1311import java.io.InputStream;
    1412import java.nio.charset.StandardCharsets;
     13import java.nio.file.Files;
     14import java.nio.file.InvalidPathException;
    1515import java.util.ArrayList;
    1616import java.util.Collection;
     
    397397                String fileDir = file.getParentFile().getAbsolutePath();
    398398                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())) {
    400400                    openAndReadXML(is);
    401401                }
    402             } catch (ScriptException | IOException | SecurityException ex) {
     402            } catch (ScriptException | IOException | SecurityException | InvalidPathException ex) {
    403403                PreferencesUtils.log(ex, "Error reading custom preferences:");
    404404            }
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java

    r12620 r13204  
    66import java.awt.Component;
    77import java.io.File;
    8 import java.io.FileOutputStream;
    98import java.io.IOException;
    109import java.io.InputStream;
     
    1413import java.nio.charset.StandardCharsets;
    1514import java.nio.file.Files;
     15import java.nio.file.InvalidPathException;
    1616import java.nio.file.StandardCopyOption;
    1717import java.util.Enumeration;
     
    115115            try (
    116116                InputStream in = downloadConnection.getResponse().getContent();
    117                 OutputStream out = new FileOutputStream(file)
     117                OutputStream out = Files.newOutputStream(file.toPath())
    118118            ) {
    119119                byte[] buffer = new byte[32_768];
     
    145145            Logging.warn(msg);
    146146            throw new DownloadException(msg, e);
    147         } catch (IOException e) {
     147        } catch (IOException | InvalidPathException e) {
    148148            if (canceled)
    149149                return;
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/NoteExporter.java

    r12671 r13204  
    55
    66import java.io.File;
    7 import java.io.FileOutputStream;
    87import java.io.IOException;
    98import java.io.OutputStream;
     9import java.nio.file.Files;
    1010
    1111import org.openstreetmap.josm.actions.ExtensionFileFilter;
     
    4040        Logging.info("exporting notes to file: " + file);
    4141        if (layer instanceof NoteLayer) {
    42             try (OutputStream os = new FileOutputStream(file);
     42            try (OutputStream os = Files.newOutputStream(file.toPath());
    4343                 NoteWriter writer = new NoteWriter(os)) {
    4444                writer.write(((NoteLayer) layer).getNoteData());
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/ValidatorErrorExporter.java

    r12671 r13204  
    55
    66import java.io.File;
    7 import java.io.FileOutputStream;
    87import java.io.IOException;
    98import java.io.OutputStream;
     9import java.nio.file.Files;
    1010
    1111import org.openstreetmap.josm.actions.ExtensionFileFilter;
     
    4444        if (layer instanceof ValidatorLayer && editLayer != null) {
    4545            Logging.info("exporting validation errors to file: " + file);
    46             try (OutputStream os = new FileOutputStream(file);
     46            try (OutputStream os = Files.newOutputStream(file.toPath());
    4747                 ValidatorErrorWriter writer = new ValidatorErrorWriter(os)) {
    4848                writer.write(editLayer.validationErrors);
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/WMSLayerExporter.java

    r12851 r13204  
    33
    44import java.io.File;
    5 import java.io.FileOutputStream;
    65import java.io.IOException;
    76import java.io.ObjectOutputStream;
     7import java.nio.file.Files;
    88
    99import org.openstreetmap.josm.data.StructUtils;
     
    3838
    3939        if (layer instanceof AbstractTileSourceLayer) {
    40             try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) {
     40            try (ObjectOutputStream oos = new ObjectOutputStream(Files.newOutputStream(file.toPath()))) {
    4141                oos.writeInt(CURRENT_FILE_VERSION); // file version
    4242                oos.writeObject(MainApplication.getMap().mapView.getCenter());
    43                 ImageryPreferenceEntry entry = new ImageryPreferenceEntry(((AbstractTileSourceLayer) layer).getInfo());
     43                ImageryPreferenceEntry entry = new ImageryPreferenceEntry(((AbstractTileSourceLayer<?>) layer).getInfo());
    4444                oos.writeObject(StructUtils.serializeStruct(entry, ImageryPreferenceEntry.class));
    4545            }
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/WMSLayerImporter.java

    r12851 r13204  
    55
    66import java.io.File;
    7 import java.io.FileInputStream;
    87import java.io.IOException;
    98import java.io.InvalidClassException;
    109import java.io.ObjectInputStream;
     10import java.nio.file.Files;
    1111import java.util.Map;
    1212
     
    4949        final ImageryLayer layer;
    5050
    51         try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file))) {
     51        try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(file.toPath()))) {
    5252            int sfv = ois.readInt();
    5353            if (sfv < 5) {
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r13130 r13204  
    2121import java.awt.event.WindowEvent;
    2222import java.io.File;
    23 import java.io.FileInputStream;
    2423import java.io.IOException;
    2524import java.io.InputStream;
     25import java.nio.file.Files;
    2626import java.text.DateFormat;
    2727import java.text.ParseException;
     
    331331        private InputStream createInputStream(File sel) throws IOException {
    332332            if (Utils.hasExtension(sel, "gpx.gz")) {
    333                 return new GZIPInputStream(new FileInputStream(sel));
     333                return new GZIPInputStream(Files.newInputStream(sel.toPath()));
    334334            } else {
    335                 return new FileInputStream(sel);
     335                return Files.newInputStream(sel.toPath());
    336336            }
    337337        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java

    r13050 r13204  
    77import java.awt.image.BufferedImage;
    88import java.io.File;
    9 import java.io.FileInputStream;
    109import java.io.FileNotFoundException;
    1110import java.io.IOException;
     11import java.nio.file.Files;
     12import java.nio.file.Paths;
    1213import java.util.ArrayList;
    1314import java.util.List;
     
    543544    }
    544545
    545     private DataSet loadDataset() throws FileNotFoundException, IllegalDataException {
     546    private DataSet loadDataset() throws IOException, IllegalDataException {
    546547        if (argInput == null) {
    547548            throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i"));
    548549        }
    549550        try {
    550             return OsmReader.parseDataSet(new FileInputStream(argInput), null);
     551            return OsmReader.parseDataSet(Files.newInputStream(Paths.get(argInput)), null);
    551552        } catch (IllegalDataException e) {
    552553            throw new IllegalDataException(tr("In .osm data file ''{0}'' - ", argInput) + e.getMessage());
Note: See TracChangeset for help on using the changeset viewer.