Ignore:
Timestamp:
2014-04-29T18:06:29+02:00 (12 years ago)
Author:
Don-vip
Message:

see #8465 - use of try-with-resource

File:
1 edited

Legend:

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

    r7005 r7030  
    383383
    384384    public static String getHandlerInfoAsJSON(String cmd) {
    385         StringWriter w = new StringWriter();
    386         PrintWriter r = new PrintWriter(w);
    387         RequestHandler handler = null;
    388         try {
    389             Class<?> c = handlers.get(cmd);
    390             if (c==null) return null;
    391             handler = handlers.get(cmd).newInstance();
    392         } catch (Exception ex) {
    393             Main.error(ex);
     385        try (StringWriter w = new StringWriter()) {
     386            PrintWriter r = new PrintWriter(w);
     387            RequestHandler handler = null;
     388            try {
     389                Class<?> c = handlers.get(cmd);
     390                if (c==null) return null;
     391                handler = handlers.get(cmd).newInstance();
     392            } catch (InstantiationException | IllegalAccessException ex) {
     393                Main.error(ex);
     394                return null;
     395            }
     396   
     397            printJsonInfo(cmd, r, handler);
     398            return w.toString();
     399        } catch (IOException e) {
     400            Main.error(e);
    394401            return null;
    395402        }
    396 
     403    }
     404
     405    private static void printJsonInfo(String cmd, PrintWriter r, RequestHandler handler) {
    397406        r.printf("{ \"request\" : \"%s\"", cmd);
    398407        if (handler.getUsage() != null) {
     
    438447        }
    439448        r.append("]}");
    440         try {
    441             return w.toString();
    442         } finally {
    443             try {
    444                 w.close();
    445             } catch (IOException ex) {
    446                 Main.warn(ex);
    447             }
    448         }
    449449    }
    450450
Note: See TracChangeset for help on using the changeset viewer.