> 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.
>