Ignore:
Timestamp:
2017-12-17T00:17:20+01:00 (23 months 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/tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r12931 r13204  
    44import java.io.BufferedInputStream;
    55import java.io.File;
    6 import java.io.FileInputStream;
    76import java.io.IOException;
    87import java.io.InputStream;
     
    1110import java.net.URL;
    1211import java.nio.charset.StandardCharsets;
     12import java.nio.file.Files;
     13import java.nio.file.InvalidPathException;
    1314import java.text.MessageFormat;
    1415import java.util.ArrayList;
     
    372373        final String langfile = "data/"+loadedCode+".lang";
    373374        try (
    374             FileInputStream fis = new FileInputStream(source);
     375            InputStream fis = Files.newInputStream(source.toPath());
    375376            JarInputStream jar = new JarInputStream(fis)
    376377        ) {
     
    384385            if (found) {
    385386                try (
    386                     FileInputStream fisTrans = new FileInputStream(source);
     387                    InputStream fisTrans = Files.newInputStream(source.toPath());
    387388                    JarInputStream jarTrans = new JarInputStream(fisTrans)
    388389                ) {
     
    397398                }
    398399            }
    399         } catch (IOException e) {
    400             // Ignore
     400        } catch (IOException | InvalidPathException e) {
    401401            Logging.trace(e);
    402402        }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r12846 r13204  
    88import java.io.BufferedReader;
    99import java.io.File;
    10 import java.io.FileInputStream;
    1110import java.io.IOException;
     11import java.io.InputStream;
    1212import java.net.URI;
    1313import java.net.URISyntaxException;
     
    403403        if (f.exists()) {
    404404            CertificateFactory fact = CertificateFactory.getInstance("X.509");
    405             try (FileInputStream is = new FileInputStream(f)) {
     405            try (InputStream is = Files.newInputStream(f.toPath())) {
    406406                return (X509Certificate) fact.generateCertificate(is);
    407407            }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r12887 r13204  
    3232import java.io.BufferedWriter;
    3333import java.io.File;
    34 import java.io.FileInputStream;
    3534import java.io.IOException;
     35import java.io.InputStream;
    3636import java.io.OutputStream;
    3737import java.io.OutputStreamWriter;
     
    4242import java.nio.file.FileSystems;
    4343import java.nio.file.Files;
     44import java.nio.file.InvalidPathException;
    4445import java.nio.file.Path;
    4546import java.security.InvalidKeyException;
     
    518519            return;
    519520        }
    520         try (FileInputStream fis = new FileInputStream(templateFile.toFile())) {
     521        try (InputStream fis = Files.newInputStream(templateFile)) {
    521522            Properties props = new Properties();
    522523            props.load(fis);
     
    581582            }
    582583            Utils.updateSystemProperty("sun.awt.fontconfig", fontconfigFile.toString());
    583         } catch (IOException ex) {
     584        } catch (IOException | InvalidPathException ex) {
    584585            Logging.error(ex);
    585586        }
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r12856 r13204  
    33
    44import java.io.File;
    5 import java.io.FileInputStream;
    6 import java.io.FileOutputStream;
    75import java.io.IOException;
    86import java.io.InputStream;
     
    119import java.io.Writer;
    1210import java.nio.charset.StandardCharsets;
     11import java.nio.file.Files;
     12import java.nio.file.InvalidPathException;
     13import java.nio.file.Paths;
    1314import java.util.ArrayList;
    1415import java.util.Collection;
     
    154155        DataSet ds = optimizedWays.iterator().next().getDataSet();
    155156        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);
    157158             OsmWriter w = OsmWriterFactory.createOsmWriter(new PrintWriter(writer), false, ds.getVersion())
    158159            ) {
     
    166167
    167168    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"))) {
    170171           return OsmReader.parseDataSet(is, null).getWays();
    171         } catch (IllegalDataException | IOException ex) {
     172        } catch (IllegalDataException | IOException | InvalidPathException ex) {
    172173            Logging.trace(ex);
    173174            return Collections.emptyList();
Note: See TracChangeset for help on using the changeset viewer.