Ignore:
Timestamp:
2014-05-01T02:34:43+02:00 (12 years ago)
Author:
Don-vip
Message:

see #8465 - global use of try-with-resources, according to

File:
1 edited

Legend:

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

    r7026 r7033  
    1111import java.io.IOException;
    1212import java.io.InputStream;
     13import java.io.OutputStream;
    1314import java.net.HttpURLConnection;
    1415import java.net.MalformedURLException;
     
    184185    }
    185186
     187    @SuppressWarnings("resource")
    186188    private Pair<String, InputStream> findZipEntryImpl(String extension, String namepart) {
    187189        if (file == null)
     
    293295        String localPath = "mirror_" + a;
    294296        destDirFile = new File(destDir, localPath + ".tmp");
    295         BufferedOutputStream bos = null;
    296         BufferedInputStream bis = null;
    297297        try {
    298298            HttpURLConnection con = connectFollowingRedirect(url, httpAccept);
    299             bis = new BufferedInputStream(con.getInputStream());
    300             FileOutputStream fos = new FileOutputStream(destDirFile);
    301             bos = new BufferedOutputStream(fos);
    302             byte[] buffer = new byte[4096];
    303             int length;
    304             while ((length = bis.read(buffer)) > -1) {
    305                 bos.write(buffer, 0, length);
    306             }
    307             Utils.close(bos);
    308             bos = null;
    309             /* close fos as well to be sure! */
    310             Utils.close(fos);
    311             fos = null;
     299            try (
     300                InputStream bis = new BufferedInputStream(con.getInputStream());
     301                OutputStream fos = new FileOutputStream(destDirFile);
     302                OutputStream bos = new BufferedOutputStream(fos)
     303            ) {
     304                byte[] buffer = new byte[4096];
     305                int length;
     306                while ((length = bis.read(buffer)) > -1) {
     307                    bos.write(buffer, 0, length);
     308                }
     309            }
    312310            localFile = new File(destDir, localPath);
    313311            if(Main.platform.rename(destDirFile, localFile)) {
     
    325323                throw e;
    326324            }
    327         } finally {
    328             Utils.close(bis);
    329             Utils.close(bos);
    330325        }
    331326
Note: See TracChangeset for help on using the changeset viewer.