Ignore:
Timestamp:
2020-08-29T07:53:16+02:00 (4 years ago)
Author:
simon04
Message:

see #19624 - use try-with-resources (PMD)

File:
1 edited

Legend:

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

    r16955 r16956  
    66import java.io.BufferedInputStream;
    77import java.io.BufferedReader;
    8 import java.io.ByteArrayInputStream;
    98import java.io.IOException;
    109import java.io.InputStream;
    1110import java.io.InputStreamReader;
     11import java.io.StringReader;
    1212import java.nio.charset.StandardCharsets;
    1313import java.util.List;
     
    6565    GeoJSONReader() {
    6666        // Restricts visibility
    67     }
    68 
    69     private void parse(InputStream inputStream) throws IllegalDataException {
    70         try (JsonParser parser = Json.createParser(inputStream)) {
    71             parse(parser);
    72         } catch (JsonParsingException e) {
    73             throw new IllegalDataException(e);
    74         }
    7567    }
    7668
     
    384376    @Override
    385377    protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException {
    386         InputStream markSupported = source.markSupported() ? source : new BufferedInputStream(source);
    387         ds.setUploadPolicy(UploadPolicy.DISCOURAGED);
    388         if (isLineDelimited(markSupported)) {
    389             BufferedReader reader = new BufferedReader(new InputStreamReader(markSupported, StandardCharsets.UTF_8));
    390             String line = null;
    391             String rs = new String(new byte[]{RECORD_SEPARATOR_BYTE}, StandardCharsets.US_ASCII);
    392             try {
    393                 while ((line = reader.readLine()) != null) {
    394                     line = Utils.strip(line, rs);
    395                     try (InputStream is = new ByteArrayInputStream(line.getBytes(StandardCharsets.UTF_8))) {
    396                         parse(is);
     378        try (InputStream markSupported = source.markSupported() ? source : new BufferedInputStream(source)) {
     379            ds.setUploadPolicy(UploadPolicy.DISCOURAGED);
     380            if (isLineDelimited(markSupported)) {
     381                try (BufferedReader reader = new BufferedReader(new InputStreamReader(markSupported, StandardCharsets.UTF_8))) {
     382                    String line;
     383                    String rs = new String(new byte[]{RECORD_SEPARATOR_BYTE}, StandardCharsets.US_ASCII);
     384                    while ((line = reader.readLine()) != null) {
     385                        line = Utils.strip(line, rs);
     386                        try (JsonParser parser = Json.createParser(new StringReader(line))) {
     387                            parse(parser);
     388                        }
    397389                    }
    398390                }
    399             } catch (IOException e) {
    400                 throw new IllegalDataException(e);
    401             }
    402         } else {
    403             parse(markSupported);
     391            } else {
     392                try (JsonParser parser = Json.createParser(markSupported)) {
     393                    parse(parser);
     394                }
     395            }
     396        } catch (IOException | JsonParsingException e) {
     397            throw new IllegalDataException(e);
    404398        }
    405399        return getDataSet();
Note: See TracChangeset for help on using the changeset viewer.