Ignore:
Timestamp:
2014-05-09T05:21:14+02:00 (12 years ago)
Author:
donvip
Message:

[josm_plugins] see #josm8465 - Java 7 code update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/api/util/HttpUtils.java

    r29736 r30436  
    4242        int length = -1;
    4343        byte[] b = new byte[1024];
    44         InputStream in = Utils.openURL(new URL(url));
    45         while( (length = in.read(b)) > 0 ) {
    46             bos.write(b, 0, length);
     44        try (InputStream in = Utils.openURL(new URL(url))) {
     45            while( (length = in.read(b)) > 0 ) {
     46                bos.write(b, 0, length);
     47            }
    4748        }
    48         Utils.close(in);
    4949
    5050        return new String(bos.toByteArray(), charset);
     
    6666
    6767        //send the post
    68         OutputStream os = con.getOutputStream();
    69         os.write(content.getBytes("UTF-8"));
    70         os.flush();
     68        try (OutputStream os = con.getOutputStream()) {
     69            os.write(content.getBytes("UTF-8"));
     70            os.flush();
     71        }
    7172
    7273        // read the response
     
    7475        int length = -1;
    7576        byte[] b = new byte[1024];
    76         InputStream in = con.getInputStream();
    77         while( (length = in.read(b)) > 0 ) {
    78             bos.write(b, 0, length);
     77        try (InputStream in = con.getInputStream()) {
     78            while( (length = in.read(b)) > 0 ) {
     79                bos.write(b, 0, length);
     80            }
    7981        }
    80         Utils.close(in);
    81         Utils.close(os);
    8282
    8383        return new String(bos.toByteArray(), responseCharset);
Note: See TracChangeset for help on using the changeset viewer.