Changeset 3007 in josm for trunk/src/org


Ignore:
Timestamp:
2010-02-17T22:03:47+01:00 (14 years ago)
Author:
Gubaer
Message:

cosmetics

File:
1 edited

Legend:

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

    r2990 r3007  
    6767    }
    6868
    69     public InputStream getZipEntry(String extension, String namepart)
    70     {
     69    /**
     70     * Replies an input stream for a file in a ZIP-file. Replies a file in the top
     71     * level directory of the ZIP file which has an extension <code>extension</code>. If more
     72     * than one files have this extension, the last file whose name includes <code>namepart</code>
     73     * is opened.
     74     *
     75     * @param extension  the extension of the file we're looking for
     76     * @param namepart the name part
     77     * @return an input stream. Null if this mirrored input stream doesn't represent a zip file or if
     78     * there was no matching file in the ZIP file
     79     */
     80    public InputStream getZipEntry(String extension, String namepart) {
    7181        InputStream res = null;
    7282        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<? extends ZipEntry> entries = zipFile.entries();
    79                 while(entries.hasMoreElements()) {
    80                     ZipEntry entry = entries.nextElement();
    81                     if(entry.getName().endsWith("."+extension)) {
    82                         /* choose any file with correct extension. When more than
     83            ZipFile zipFile = new ZipFile(file);
     84            ZipEntry resentry = null;
     85            Enumeration<? extends ZipEntry> entries = zipFile.entries();
     86            while (entries.hasMoreElements()) {
     87                ZipEntry entry = entries.nextElement();
     88                if (entry.getName().endsWith("." + extension)) {
     89                    /* choose any file with correct extension. When more than
    8390                        one file, prefer the one which matches namepart */
    84                         if(resentry == null || entry.getName().indexOf(namepart) >= 0) {
    85                             resentry = entry;
    86                         }
     91                    if (resentry == null || entry.getName().indexOf(namepart) >= 0) {
     92                        resentry = entry;
    8793                    }
    8894                }
    89                 if(resentry != null) {
    90                     res = zipFile.getInputStream(resentry);
    91                 }
    92                 else {
    93                     zipFile.close();
    94                 }
     95            }
     96            if (resentry != null) {
     97                res = zipFile.getInputStream(resentry);
     98            } else {
     99                zipFile.close();
    95100            }
    96101        } catch (Exception e) {
    97             System.err.println(tr("Warning: failed to handle zip file ''{0}''. Exception was: {1}", file.getName(), e.toString()));
     102            System.err.println(tr("Warning: failed to open file with extension ''{2}'' and namepart ''{3}'' in zip file ''{0}''. Exception was: {1}", file.getName(), e.toString(), extension, namepart));
    98103        }
    99104        return res;
Note: See TracChangeset for help on using the changeset viewer.