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

Images loading differerntly from jar vs on disk

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • tools
    • None
    • jar
    • sparc
    • solaris_2.5.1

      > In the following code I get a different response depending on whether
      > the class file and images are left on the disk or placed in a jar file.
      > In the latter case the is.available() always returns 1, regardless of
      > the number of bytes really available:
      >
      > Image loadImageAsResource(String resourceName)
      > {
      > Image image = null;
      >
      > try
      > {
      > InputStream is =
      > this.getClass().getResourceAsStream(resourceName);
      > byte[] bytes = new byte[is.available()];
      >
      > // !!!!!!! ^^^^^^^ returns 1 if in class and img
      > // are in jar. Otherwise, returns a correct number
      >
      > is.read(bytes);
      > image = this.getToolkit().createImage(bytes);
      > is.close();
      > }
      > catch (Exception resourceError)
      > {
      > // react to it
      > }
      >
      > return (image);
      > }
      >
      > The loading class is not part of a package, but I found out that it does
      > not really matter. The input stream returned is a ZipFile, from
      > java.util.zip package.
      >

            zlisunw Zhenghua Li (Inactive)
            jeff Jeff Dinkins
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: