Changeset 29528 in osm for applications/viewer/jmapviewer


Ignore:
Timestamp:
2013-04-21T17:34:47+02:00 (11 years ago)
Author:
donvip
Message:

[jmapviewer] fix #josm8570 - streams not closed

Location:
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java

    r29516 r29528  
    304304        protected byte[] loadTileInBuffer(URLConnection urlConn) throws IOException {
    305305            input = urlConn.getInputStream();
    306             ByteArrayOutputStream bout = new ByteArrayOutputStream(input.available());
    307             byte[] buffer = new byte[2048];
    308             boolean finished = false;
    309             do {
    310                 int read = input.read(buffer);
    311                 if (read >= 0) {
    312                     bout.write(buffer, 0, read);
    313                 } else {
    314                     finished = true;
    315                 }
    316             } while (!finished);
    317             if (bout.size() == 0)
    318                 return null;
    319             return bout.toByteArray();
     306            try {
     307                ByteArrayOutputStream bout = new ByteArrayOutputStream(input.available());
     308                byte[] buffer = new byte[2048];
     309                boolean finished = false;
     310                do {
     311                    int read = input.read(buffer);
     312                    if (read >= 0) {
     313                        bout.write(buffer, 0, read);
     314                    } else {
     315                        finished = true;
     316                    }
     317                } while (!finished);
     318                if (bout.size() == 0)
     319                    return null;
     320                return bout.toByteArray();
     321            } finally {
     322                input.close();
     323                input = null;
     324            }
    320325        }
    321326
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmTileLoader.java

    r29516 r29528  
    5858                    } else {
    5959                        input = conn.getInputStream();
    60                         tile.loadImage(input);
    61                         input.close();
    62                         input = null;
     60                        try {
     61                            tile.loadImage(input);
     62                        } finally {
     63                            input.close();
     64                            input = null;
     65                        }
    6366                    }
    6467                    tile.setLoaded(true);
Note: See TracChangeset for help on using the changeset viewer.