You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Gary L Peskin <ga...@firstech.com> on 2000/12/06 21:35:41 UTC

.properties files within JARs

There's been an interesting discussion, instigated by Frank Griffin,
over on the ibmpub.java.os390 newsgroup (server ncc.hursley.ibm.com). 
You can access the discussion here:  

http://ncc.hursley.ibm.com/newsgroups/ncc/nccnews?ibmpub.java.os390+1247

This web interface kind of sucks but it's better than nothing.  The
discussion is entitled "Conversion of .properties files within JARs".

What's happening in a nutshell is that in
javax.xml.transform.TransformerFactory.findFactory (line 370), we're
looking for a properties file in the classpath of the form:

"META-INF/services/" + factoryId

If we find it, we read the only line in it with an InputStreamReader.

The code (slightly edited) looks like this:

  ClassLoader cl = TransformerFactory.class.getClassLoader();
  InputStream is = null;
  if (cl == null)
    is = ClassLoader.getSystemResourceAsStream(serviceId);
  else
    is = cl.getResourceAsStream(serviceId);

  if (is != null)
  {
     BufferedReader rd = new BufferedReader(new InputStreamReader(is));
     foundFactory = rd.readLine();
     rd.close();
  }

The problem is that that the InputStreamReader assumes that the
properties file is in the platform default encoding.  On ASCII
platforms, this is not a problem.  However, on EBCDIC platforms
(OS/390), we have the following problem:  If the properties file is in
the .jar, it will be in ASCII since that is how we distribute
xalan.jar.  However, if someone needs to edit that file, they would
extract it from the .jar and convert it to EBCDIC or just make a new
file in EBCDIC, the default encoding for the platform.  This would allow
them to use the OS/390 based editors to edit their file.  So, we need to
tell whether our stream represents an EBCDIC encoded stream or an ASCII
encoded stream.

One way to do this would be to issue a get(System)Resource instead of
get(System)ResourceAsStream.  These return a URL instead of a stream. 
Then, in a platform dependent way:

  BufferedReader rd;
  String platformName = System.getProperty("os.name", "other");
  if (platformName.equals("OS/390"))
  {
    if url-indicates-from-a-jar
      rd = new BufferedReader(new InputStreamReader(url.openStream(),
"8859_1");
    else
      rd = new BufferedReader(new InputStreamReader(url.openStream());
  }
  else
     rd = new BufferedReader(new InputStreamReader(url.openStream()));

This kind of sucks but I don't see an alternative right now.  Any
thoughts?

What I'd really like is to have two methods:
  System.getResourceAsReader -and-
  System.getSystemResourceAsReader

How do I go about suggesting this to the Sun JDK people?

Gary