Ignore:
Timestamp:
2013-08-14T13:12:50+02:00 (11 years ago)
Author:
bastiK
Message:

fixed #8686 - Allow ZIP files whose paths are relative to the ZIP root in JOSM's map styling

File:
1 edited

Legend:

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

    r6090 r6148  
    2222
    2323import org.openstreetmap.josm.Main;
     24import org.openstreetmap.josm.tools.Pair;
    2425import org.openstreetmap.josm.tools.Utils;
    2526
     
    9192
    9293    /**
    93      * Replies an input stream for a file in a ZIP-file. Replies a file in the top
    94      * level directory of the ZIP file which has an extension <code>extension</code>. If more
    95      * than one files have this extension, the last file whose name includes <code>namepart</code>
     94     * Looks for a certain entry inside a zip file and returns the entry path.
     95     *
     96     * Replies a file in the top level directory of the ZIP file which has an
     97     * extension <code>extension</code>. If more than one files have this
     98     * extension, the last file whose name includes <code>namepart</code>
    9699     * is opened.
    97100     *
    98101     * @param extension  the extension of the file we're looking for
    99102     * @param namepart the name part
    100      * @return an input stream. Null if this mirrored input stream doesn't represent a zip file or if
    101      * there was no matching file in the ZIP file
    102      */
     103     * @return The zip entry path of the matching file. Null if this mirrored
     104     * input stream doesn't represent a zip file or if there was no matching
     105     * file in the ZIP file.
     106     */
     107    public String findZipEntryPath(String extension, String namepart) {
     108        Pair<String, InputStream> ze = findZipEntryImpl(extension, namepart);
     109        if (ze == null) return null;
     110        return ze.a;
     111    }
     112
     113    /**
     114     * Like {@link #findZipEntryPath}, but returns the corresponding InputStream.
     115     */
     116    public InputStream findZipEntryInputStream(String extension, String namepart) {
     117        Pair<String, InputStream> ze = findZipEntryImpl(extension, namepart);
     118        if (ze == null) return null;
     119        return ze.b;
     120    }
     121
     122    @Deprecated // use findZipEntryInputStream
    103123    public InputStream getZipEntry(String extension, String namepart) {
     124        return findZipEntryInputStream(extension, namepart);
     125    }
     126
     127    private Pair<String, InputStream> findZipEntryImpl(String extension, String namepart) {
    104128        if (file == null)
    105129            return null;
    106         InputStream res = null;
     130        Pair<String, InputStream> res = null;
    107131        try {
    108132            ZipFile zipFile = new ZipFile(file);
     
    120144            }
    121145            if (resentry != null) {
    122                 res = zipFile.getInputStream(resentry);
     146                InputStream is = zipFile.getInputStream(resentry);
     147                res = Pair.create(resentry.getName(), is);
    123148            } else {
    124149                Utils.close(zipFile);
Note: See TracChangeset for help on using the changeset viewer.