Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4200501

getResourceAsStream returns poor InputStream

    XMLWordPrintable

Details

    • generic, x86
    • generic, windows_95, windows_nt

    Description



      Name: gsC80088 Date: 01/04/99


      Against JDK 1.2beta42:

      getResourceAsStream returns poor InputStream
      with returning always 1 to calling available().
      This results in poor performance.
      (Review ID: 40856)
      ======================================================================

      Name: gsC80088 Date: 03/01/99


      I am having problems with with Class.getResourceAsStream(). I have seen several
      bugs written about simailar problems,
      all of which seem to have been marked as fixed.
      For some reason, I am still having problems.


      Configuration:
           Type of Java App: JApplet
           Browser: IE 4.0 or Netscape 4.5
           JRE: Java Plugin 1.1.1.
           Platform : Windows NT
           JDK 1.1.7

      Symptoms :

      I have two jar files A.jar and B.jar.
      I want to call getResourceAsStream()on a resource file that resides in A.jar. The call to
      getResourceAsStream() resides in a class in B.jar.

      Example:
      A.jar contains MyResource.txt

      B.jar contains B.class which has the following
      class:

      public class B {
        public void getMyResource() {
           String resource = "MyResource.txt";
           InputStream inputStream =
             marker.getClass().getResourceAsStream(resource);

        // marker is an Object reference that refers
        // to my JApplet class. MyResource.txt is
        // in the same directory as the JApplet class.
      }
      }

      Case 1) The above example will always return null
      for inputStream if the code is run using JavaPlugin 1.1 from either IE or Netscape.

      Case 2) If I run the same code as an application
      using classes.zip and NO jar files, the resource
      is found.

      Case 3) If I run the same code using JRE 1.1.7
      with jar files, the resource is also found with
      no problem.

      Case 4) If I run the same code using Netscape,
      with NO jar files, with Java Plugin 1.1, the
      resource is found as well.

      I have proven that if I try to get the resource
      in A.jar using a call from a method contained in
      A.jar (namely from the JApplet itself), the resource is found. It appears that there is
      some incompatability between Java Plugin and
      resources in other jar files or other packages.

      I have eliminated the possibility of this being a
      file extension problem by renaming the resource
      file MyResource.gif. The file is still not found
      when accessed from B.jar. So I got crazy and
      made one big horkin jar file containing the
      contents of A and B. The resource is still not
      found! It's as if the resource can't be found
      when accessed from outside of it's package. So
      you say, create an accessor method for the
      resource and put the accessor in the package
      where the resource resides. This didn't work
      either.

      Unfortunately, I have to use the Java Plugin for
      this Applet, so I have to come up with some
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              jccollet Jean-Christophe Collet (Inactive)
              gstone Greg Stone
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: