Ignore:
Timestamp:
2011-05-01T21:56:49+02:00 (13 years ago)
Author:
jttt
Message:

Improved wms cache

  • files saved in original format (no need to recode to png)
  • possibility to tile with different pos/ppd that overlaps current tile
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r3979 r4065  
    33
    44import java.awt.Color;
     5import java.io.File;
     6import java.io.IOException;
     7import java.io.InputStream;
     8import java.io.OutputStream;
    59import java.util.Collection;
    610
     
    1519    }
    1620
    17     public static <T> boolean exists(Iterable collection, Class<? extends T> klass) {
     21    public static <T> boolean exists(Iterable<T> collection, Class<? extends T> klass) {
    1822        for (Object item : collection) {
    1923            if (klass.isInstance(item))
     
    3135    }
    3236
    33     public static <T> T find(Iterable collection, Class<? extends T> klass) {
     37    @SuppressWarnings("unchecked")
     38    public static <T> T find(Iterable<? super T> collection, Class<? extends T> klass) {
    3439        for (Object item : collection) {
    35             if (klass.isInstance(item)) {
    36                 @SuppressWarnings("unchecked") T res = (T) item;
    37                 return res;
    38             }
     40            if (klass.isInstance(item))
     41                return (T) item;
    3942        }
    4043        return null;
     
    6063            return b;
    6164        } else {
    62             if (a < c) {
     65            if (a < c)
    6366                return a;
    64             }
    6567            return c;
    6668        }
     
    160162    }
    161163
     164
     165    public static int copyStream(InputStream source, OutputStream destination) throws IOException {
     166        int count = 0;
     167        byte[] b = new byte[512];
     168        int read;
     169        while ((read = source.read(b)) != -1) {
     170            count += read;
     171            destination.write(b, 0, read);
     172        }
     173        return count;
     174    }
     175
     176
     177
    162178    public static Color complement(Color clr) {
    163179        return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha());
    164180    }
     181
     182    public static boolean deleteDirectory(File path) {
     183        if( path.exists() ) {
     184            File[] files = path.listFiles();
     185            for(int i=0; i<files.length; i++) {
     186                if(files[i].isDirectory()) {
     187                    deleteDirectory(files[i]);
     188                }
     189                else {
     190                    files[i].delete();
     191                }
     192            }
     193        }
     194        return( path.delete() );
     195    }
    165196}
Note: See TracChangeset for help on using the changeset viewer.