Hi Alexander,
Thanks for testing Allesandro's solution.
- Don
On Nov 26, 2003, at 10:19 AM, alexander sokolov wrote:
> Hi Don,
>
> Thanks for the quick reply.
> I checked the Alessandro Foresi solution. It also works fine using Sun
> jdk 1.4.2 on
> Windows, OS X and Linux. Just fine.
> So, it seems we have the same problem and two solutions.
>
> Thanks for the great soft and excellent support.
>
> Alexander
>
> Don Dietrick wrote:
>
>> Hi Alexander,
>>
>> Thanks for the heads-up and the proposed solutions. I think I prefer
>> the backward compatible approach since we don't have a jdk 1.4
>> requirement on OpenMap yet.
>>
>> There have been other reports of problems getting files out of jar
>> files, and I think they are all related.
>>
>> Alessandro Foresi <alefor@gmx.de> wrote in with this solution:
>>
>> I had a similar problem, and patched JarInputReader.java line 72 from
>> openmap-4.5.4:
>> jarFile = new JarFile(URLDecoder.decode(jarFileName, "UTF-8"));
>>
>> Does this solve your problem as well, or does this fix a different
>> problem? I don't have jdk 1.4.2 to test on.
>>
>> - Don
>>
>> On Nov 25, 2003, at 6:11 AM, alexander sokolov wrote:
>>
>>> Hi,
>>>
>>> I have a problem reading shape files from a jar using Java Web
>>> Start. Actually it used to work well before the java version 1.4.2.
>>> It seems this problem appears when the path to the jar contains
>>> spaces (as default, the JWS allocates its cache in the directory
>>> with spaces at least on Windows and OS X).
>>>
>>> As a workaround we can use
>>>
>>> inputStream =
>>> Thread.currentThread().getContextClassLoader().getResourceAsStream(ja
>>> rE ntryName);
>>>
>>> instead of
>>>
>>> jarFile = new JarFile(jarFileName);
>>> JarEntry entry = jarFile.getJarEntry(jarEntryName);
>>> inputStream = jarFile.getInputStream(entry);
>>>
>>> What do you think?
>>>
>>> Regards
>>>
>>> Alexander
>>>
>>> PS Modified JarInputReader.java is in the attachment
>>> //
>>> *********************************************************************
>>> *
>>> //
>>> // <copyright>
>>> //
>>> // BBN Technologies, a Verizon Company
>>> // 10 Moulton Street
>>> // Cambridge, MA 02138
>>> // (617) 873-8000
>>> //
>>> // Copyright (C) BBNT Solutions LLC. All rights reserved.
>>> //
>>> // </copyright>
>>> //
>>> *********************************************************************
>>> *
>>> //
>>> // $Source: /cvs/openmap/openmap/src/openmap/com/bbn/openmap/io/
>>> JarInputReader.java,v $
>>> // $RCSfile: JarInputReader.java,v $
>>> // $Revision: 1.1.1.1 $
>>> // $Date: 2003/03/03 21:58:02 $
>>> // $Author: dietrick $
>>> //
>>> //
>>> *********************************************************************
>>> *
>>>
>>>
>>> package com.bbn.openmap.io;
>>>
>>> import java.io.*;
>>> import java.net.*;
>>> import java.util.jar.*;
>>> import com.bbn.openmap.util.Debug;
>>>
>>> /**
>>> * An InputReader to handle entries in a Jar file.
>>> */
>>> public class JarInputReader extends StreamInputReader {
>>>
>>> /** Where to go to hook up with a resource. */
>>> protected URL inputURL = null;
>>>
>>> protected JarFile jarFile = null;
>>> protected String jarFileName = null;
>>> protected String jarEntryName = null;
>>>
>>> /**
>>> * Create a JarInputReader win the path to a jar file, and the
>>> * entry name. The entry name should be a path to the entry from
>>> * the internal root of the jar file.
>>> */
>>> public JarInputReader(String jarFilePath, String jarEntryName)
>>> throws IOException {
>>>
>>> if (Debug.debugging("binaryfile")) {
>>> Debug.output("JarInputReader created for " + jarEntryName +
>>> " in " + jarFilePath);
>>> }
>>> this.jarFileName = jarFilePath;
>>> this.jarEntryName = jarEntryName;
>>> reopen();
>>> name = jarFilePath + "!" + jarEntryName;
>>> }
>>>
>>> /**
>>> * Reset the InputStream to the beginning, by closing the
>>> * current connection and reopening it.
>>> */
>>> public void reopen() throws IOException {
>>> super.reopen();
>>>
>>> Debug.message("binaryfile", "JarInputReader: reopening jarFile " +
>>> jarFileName);
>>> if (jarFile != null) jarFile.close();
>>> jarFile = null;
>>>
>>> // Suggestion by sokolov@ecology.su.se:
>>> // It seems that starting from jdk 1.4.2 the original code
>>> /*
>>> jarFile = new JarFile(jarFileName);
>>> JarEntry entry = jarFile.getJarEntry(jarEntryName);
>>> inputStream = jarFile.getInputStream(entry);
>>> */
>>> // does not like spaces in the jarFileName (even %20).
>>> // But we can try to get the data using getResourceAsStream,
>>> // So, it can look like
>>> /*
>>> ClassLoader classLoader =
>>> Thread.currentThread().getContextClassLoader();
>>> inputStream = classLoader.getResourceAsStream(jarEntryName);
>>> */
>>> // Or we can try to be back compatible and use
>>>
>>> ClassLoader classLoader =
>>> Thread.currentThread().getContextClassLoader();
>>> try {
>>> jarFile = new JarFile(jarFileName);
>>> JarEntry entry = jarFile.getJarEntry(jarEntryName);
>>> inputStream = jarFile.getInputStream(entry);
>>> } catch (java.util.zip.ZipException zipEx) {
>>> inputStream = classLoader.getResourceAsStream(jarEntryName);
>>> }
>>> // end of suggestion
>>>
>>> if (inputStream == null) {
>>> Debug.error("JarInputReader: Problem getting input stream for " +
>>> jarEntryName + " in " + jarFileName);
>>> }
>>> }
>>>
>>> /**
>>> * Closes the underlying file
>>> *
>>> * @exception IOException Any IO errors encountered in accessing the
>>> file
>>> */
>>> public void close() throws IOException {
>>> jarFile.close();
>>> super.close();
>>> }
>>>
>>> }
>>
>>
>>
>
> --
> Alexander Sokolov
> Department of Systems Ecology, Stockholm University,
> SE-10691 Stockholm, Sweden
> Fax +46 (0)8 15 8417
> Phone +46 (0)8 16 1739
> Mobile +46 (0)70 939 0955
>
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]Received on Wed Nov 26 12:48:12 2003
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:37 EDT