Ignore:
Timestamp:
24.01.2010 14:20:12 (2 years ago)
Author:
stoecker
Message:

close #4418 - support zip files for styles and presets

File:
1 edited

Legend:

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

    r2832 r2889  
    1313import java.net.URL; 
    1414import java.net.URLConnection; 
     15import java.util.Enumeration; 
     16import java.util.zip.ZipEntry; 
     17import java.util.zip.ZipFile; 
    1518 
    1619import org.openstreetmap.josm.Main; 
     
    6265            throw new IOException(); 
    6366        fs = new FileInputStream(file); 
     67    } 
     68 
     69    public InputStream getZipEntry(String extension, String namepart) 
     70    { 
     71        InputStream res = null; 
     72        try { 
     73            if(file != null && (file.getName().endsWith(".zip") 
     74            || file.getName().endsWith(".ZIP"))) 
     75            { 
     76                ZipFile zipFile = new ZipFile(file); 
     77                ZipEntry resentry = null; 
     78                Enumeration entries = zipFile.entries(); 
     79                while(entries.hasMoreElements()) { 
     80                    ZipEntry entry = (ZipEntry)entries.nextElement(); 
     81                    if(entry.getName().endsWith("."+extension)) { 
     82                        /* choose any file with correct extension. When more than 
     83                        one file, prefer the one which matches namepart */ 
     84                        if(resentry == null || entry.getName().indexOf(namepart) >= 0) { 
     85                            resentry = entry; 
     86                        } 
     87                    } 
     88                } 
     89                if(resentry != null) { 
     90                    res = zipFile.getInputStream(resentry); 
     91                } 
     92                else { 
     93                    zipFile.close(); 
     94                } 
     95            } 
     96        } catch (Exception e) { 
     97            System.err.println(tr("Warning: failed to handle zip file ''{0}''. Exception was: {1}", file.getName(), e.toString())); 
     98        } 
     99        return res; 
    64100    } 
    65101 
Note: See TracChangeset for help on using the changeset viewer.