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/io
Files:
5 edited

Legend:

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

    r12856 r13204  
    55import java.io.BufferedOutputStream;
    66import java.io.File;
    7 import java.io.FileInputStream;
    8 import java.io.FileOutputStream;
    97import java.io.IOException;
    108import java.nio.charset.StandardCharsets;
     9import java.nio.file.Files;
     10import java.nio.file.InvalidPathException;
    1111import java.util.concurrent.TimeUnit;
    1212
     
    185185     */
    186186    private void loadFromDisk() throws T {
    187         try (BufferedInputStream input = new BufferedInputStream(new FileInputStream(path))) {
     187        try (BufferedInputStream input = new BufferedInputStream(Files.newInputStream(path.toPath()))) {
    188188            this.data = new byte[input.available()];
    189189            if (input.read(this.data) < this.data.length) {
    190190                Logging.error("Failed to read expected contents from "+path);
    191191            }
    192         } catch (IOException e) {
     192        } catch (IOException | InvalidPathException e) {
    193193            Logging.trace(e);
    194194            if (!isOffline()) {
     
    202202     */
    203203    private void saveToDisk() {
    204         try (BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(path))) {
     204        try (BufferedOutputStream output = new BufferedOutputStream(Files.newOutputStream(path.toPath()))) {
    205205            output.write(this.data);
    206206            output.flush();
    207         } catch (IOException e) {
     207        } catch (IOException | InvalidPathException e) {
    208208            Logging.error(e);
    209209        }
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r12856 r13204  
    88import java.io.Closeable;
    99import java.io.File;
    10 import java.io.FileInputStream;
    1110import java.io.IOException;
    1211import java.io.InputStream;
     
    218217            }
    219218        }
    220         return new FileInputStream(file);
     219        return Files.newInputStream(file.toPath());
    221220    }
    222221
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r12772 r13204  
    33
    44import java.io.File;
    5 import java.io.FileInputStream;
    6 import java.io.FileOutputStream;
    75import java.io.IOException;
    86import java.io.InputStream;
    97import java.io.OutputStream;
    108import java.nio.charset.StandardCharsets;
     9import java.nio.file.Files;
    1110import java.util.zip.GZIPInputStream;
    1211import java.util.zip.GZIPOutputStream;
     
    150149     */
    151150    public static InputStream getUncompressedFileInputStream(File file) throws IOException {
    152         FileInputStream in = new FileInputStream(file);
     151        InputStream in = Files.newInputStream(file.toPath());
    153152        try {
    154153            return byExtension(file.getName()).getUncompressedInputStream(in);
     
    188187     */
    189188    public static OutputStream getCompressedFileOutputStream(File file) throws IOException {
    190         FileOutputStream out = new FileOutputStream(file);
     189        OutputStream out = Files.newOutputStream(file.toPath());
    191190        try {
    192191            return byExtension(file.getName()).getCompressedOutputStream(out);
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r12620 r13204  
    77import java.io.BufferedInputStream;
    88import java.io.File;
    9 import java.io.FileInputStream;
    109import java.io.FileNotFoundException;
    1110import java.io.IOException;
     
    1514import java.net.URISyntaxException;
    1615import java.nio.charset.StandardCharsets;
     16import java.nio.file.Files;
    1717import java.util.ArrayList;
    1818import java.util.Collection;
     
    715715            }
    716716        } else {
    717             try {
    718                 return new FileInputStream(sessionFile);
    719             } catch (FileNotFoundException ex) {
    720                 throw new IOException(ex);
    721             }
     717            return Files.newInputStream(sessionFile.toPath());
    722718        }
    723719    }
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r12778 r13204  
    44import java.io.BufferedOutputStream;
    55import java.io.File;
    6 import java.io.FileNotFoundException;
    7 import java.io.FileOutputStream;
    86import java.io.IOException;
    97import java.io.OutputStream;
    108import java.io.OutputStreamWriter;
    119import java.nio.charset.StandardCharsets;
     10import java.nio.file.Files;
    1211import java.util.ArrayList;
    1312import java.util.Collection;
     
    331330     */
    332331    public void write(File f) throws IOException {
    333         try (OutputStream out = new FileOutputStream(f)) {
     332        try (OutputStream out = Files.newOutputStream(f.toPath())) {
    334333            write(out);
    335         } catch (FileNotFoundException e) {
    336             throw new IOException(e);
    337334        }
    338335    }
Note: See TracChangeset for help on using the changeset viewer.