Changeset 16769 in osm for applications/viewer


Ignore:
Timestamp:
2009-08-02T14:36:37+02:00 (15 years ago)
Author:
guggis
Message:

towards a fix for #3142: JOSM applet class no longer functional

File:
1 edited

Legend:

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

    r16768 r16769  
    2121import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    2222import org.openstreetmap.gui.jmapviewer.interfaces.TileSource.TileUpdate;
     23import static org.openstreetmap.josm.tools.I18n.tr;
    2324
    2425/**
     
    5354     * @param cacheDir
    5455     */
    55     public OsmFileCacheTileLoader(TileLoaderListener map, File cacheDir) {
     56    public OsmFileCacheTileLoader(TileLoaderListener map, File cacheDir) throws SecurityException{
    5657        super(map);
    57         String tempDir = System.getProperty("java.io.tmpdir");
     58        String tempDir = null;
    5859        String userName = System.getProperty("user.name");
    5960        try {
     61            tempDir = System.getProperty("java.io.tmpdir");
     62        } catch(SecurityException e) {
     63            log.warning(tr("Failed to access system property ''{0}'' for security reasons. Exception was: {1}", "java.io.tmpdir", e.toString()));
     64            throw e; // rethrow
     65        }
     66        try {
    6067            if (cacheDir == null) {
    61                 if (tempDir == null) {
     68                if (tempDir == null)
    6269                    throw new IOException("No temp directory set");
    63                 }
    6470                String subDirName = "JMapViewerTiles";
    6571                // On Linux/Unix systems we do not have a per user tmp directory.
     
    7076            }
    7177            log.finest("Tile cache directory: " + cacheDir);
    72             if (!cacheDir.exists() && !cacheDir.mkdirs()) {
     78            if (!cacheDir.exists() && !cacheDir.mkdirs())
    7379                throw new IOException();
    74             }
    7580            cacheDirBase = cacheDir.getAbsolutePath();
    7681        } catch (Exception e) {
     
    8085
    8186    /**
    82      * Create a OSMFileCacheTileLoader with system property temp dir. 
     87     * Create a OSMFileCacheTileLoader with system property temp dir.
    8388     * If not set an IOException will be thrown.
    8489     * @param map
    8590     */
    86     public OsmFileCacheTileLoader(TileLoaderListener map) {
     91    public OsmFileCacheTileLoader(TileLoaderListener map) throws SecurityException {
    8792        this(map, null);
    8893    }
    8994
     95    @Override
    9096    public Runnable createTileLoaderJob(final TileSource source, final int tilex, final int tiley, final int zoom) {
    9197        return new FileLoadJob(source, tilex, tiley, zoom);
     
    120126            }
    121127            tileCacheDir = new File(cacheDirBase, source.getName());
    122             if (!tileCacheDir.exists())
     128            if (!tileCacheDir.exists()) {
    123129                tileCacheDir.mkdirs();
     130            }
    124131            if (loadTileFromFile())
    125132                return;
     
    200207                tile.setImage(Tile.ERROR_IMAGE);
    201208                listener.tileLoadingFinished(tile, false);
    202                 if (input == null)
     209                if (input == null) {
    203210                    System.err.println("failed loading " + zoom + "/" + tilex + "/" + tiley + " " + e.getMessage());
     211                }
    204212            } finally {
    205213                tile.loading = false;
     
    249257            do {
    250258                int read = input.read(buffer);
    251                 if (read >= 0)
     259                if (read >= 0) {
    252260                    bout.write(buffer, 0, read);
    253                 else
     261                } else {
    254262                    finished = true;
     263                }
    255264            } while (!finished);
    256265            if (bout.size() == 0)
Note: See TracChangeset for help on using the changeset viewer.