Re: [OpenMap Users] JarInputReader suggestion

From: Don Dietrick <dietrick@bbn.com>
Date: Wed Nov 26 2003 - 09:45:00 EST

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(jarE
> 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();
> }
>
> }

--
[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 09:46:09 2003

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:37 EDT