Ignore:
Timestamp:
2014-10-19T01:27:04+02:00 (10 years ago)
Author:
donvip
Message:

[josm_plugins] fix java 7 warnings / global usage of try-with-resource

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/NanoLog/src/nanolog/NanoLogLayer.java

    r30737 r30738  
    103103        final SimpleDateFormat fmt = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SS");
    104104        List<NanoLogEntry> result = new ArrayList<>();
    105         BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
    106         while( r.ready() ) {
    107             String line = r.readLine();
    108             if( line != null ) {
    109                 Matcher m = NANOLOG_LINE.matcher(line);
    110                 if( m.matches() ) {
    111                     String time = m.group(1);
    112                     String message = m.group(2);
    113                     String lat = m.group(3);
    114                     String lon = m.group(4);
    115                     String dir = m.group(5);
    116                     Date timeDate = null;
    117                     try {
    118                         timeDate = fmt.parse(time);
    119                     } catch( ParseException e ) {
    120                     }
    121                     if( message == null || message.length() == 0 || timeDate == null )
    122                         continue;
    123                     LatLon pos = null;
    124                     Integer direction = null;
    125                     if( lat != null && lon != null ) {
    126                         try {
    127                             pos = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
    128                             direction = new Integer(dir);
    129                         } catch( NumberFormatException e ) {
    130                             // well...
    131                         }
    132                     }
    133                     NanoLogEntry entry = new NanoLogEntry(timeDate, message, pos, direction);
    134                     result.add(entry);
    135                 }
    136             }
    137         }
    138         r.close();
     105        try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"))) {
     106                while( r.ready() ) {
     107                    String line = r.readLine();
     108                    if( line != null ) {
     109                        Matcher m = NANOLOG_LINE.matcher(line);
     110                        if( m.matches() ) {
     111                            String time = m.group(1);
     112                            String message = m.group(2);
     113                            String lat = m.group(3);
     114                            String lon = m.group(4);
     115                            String dir = m.group(5);
     116                            Date timeDate = null;
     117                            try {
     118                                timeDate = fmt.parse(time);
     119                            } catch( ParseException e ) {
     120                            }
     121                            if( message == null || message.length() == 0 || timeDate == null )
     122                                continue;
     123                            LatLon pos = null;
     124                            Integer direction = null;
     125                            if( lat != null && lon != null ) {
     126                                try {
     127                                    pos = new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
     128                                    direction = new Integer(dir);
     129                                } catch( NumberFormatException e ) {
     130                                    // well...
     131                                }
     132                            }
     133                            NanoLogEntry entry = new NanoLogEntry(timeDate, message, pos, direction);
     134                            result.add(entry);
     135                        }
     136                    }
     137                }
     138        }
    139139        return result;
    140140    }
Note: See TracChangeset for help on using the changeset viewer.