Ignore:
Timestamp:
2009-02-28T20:34:43+01:00 (16 years ago)
Author:
stoecker
Message:

patch by xeen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/Cache.java

    r13645 r13927  
    44import java.io.File;
    55import java.io.FileFilter;
     6import java.math.BigInteger;
     7import java.security.MessageDigest;
    68import java.util.Date;
    79import java.util.Iterator;
     
    911import java.util.TreeMap;
    1012import javax.imageio.*;
     13
    1114
    1215import org.openstreetmap.josm.Main;
     
    127130    }
    128131
    129     private String clean(String ident) {
    130         return ident.replaceAll("[^a-zA-Z0-9]", "");
     132    private static String getUniqueFilename(String ident) {
     133        try {
     134            MessageDigest md = MessageDigest.getInstance("MD5");
     135            BigInteger number = new BigInteger(1, md.digest(ident.getBytes()));
     136            return number.toString(16);
     137        } catch(Exception e) {
     138            // Fall back. Remove unsuitable characters and some random ones to shrink down path length.
     139            // Limit it to 70 characters, that leaves about 190 for the path on Windows/NTFS
     140            ident = ident.replaceAll("[^a-zA-Z0-9]", "");
     141            ident = ident.replaceAll("[acegikmoqsuwy]", "");
     142            return ident.substring(ident.length() - 70);
     143        }
    131144    }
    132145
    133146    private File getPath(String ident) {
    134         return new File(dir, clean(ident) + ".png");
     147        return new File(dir, getUniqueFilename(ident) + ".png");
    135148    }
    136149}
Note: See TracChangeset for help on using the changeset viewer.