diff options
Diffstat (limited to 'libjava/gnu/java/awt/image/ImageDecoder.java')
-rw-r--r-- | libjava/gnu/java/awt/image/ImageDecoder.java | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/libjava/gnu/java/awt/image/ImageDecoder.java b/libjava/gnu/java/awt/image/ImageDecoder.java index 4d3fbec..d44efce 100644 --- a/libjava/gnu/java/awt/image/ImageDecoder.java +++ b/libjava/gnu/java/awt/image/ImageDecoder.java @@ -48,6 +48,10 @@ public abstract class ImageDecoder implements ImageProducer Vector consumers = new Vector (); String filename; URL url; + byte[] data; + int offset; + int length; + InputStream input; public static ColorModel cm; @@ -69,6 +73,13 @@ public abstract class ImageDecoder implements ImageProducer this.url = url; } + public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength) + { + data = imagedata; + offset = imageoffset; + length = imagelength; + } + public void addConsumer (ImageConsumer ic) { consumers.addElement (ic); @@ -90,11 +101,22 @@ public abstract class ImageDecoder implements ImageProducer Vector list = (Vector) consumers.clone (); try { - FileInputStream is = (url == null) ? new FileInputStream (filename) : - (FileInputStream) url.openStream(); - - produce (list, is); - } + // Create the input stream here rather than in the + // ImageDecoder constructors so that exceptions cause + // imageComplete to be called with an appropriate error + // status. + if (url != null) + input = url.openStream(); + else + { + if (filename != null) + input = new FileInputStream (filename); + else + input = new ByteArrayInputStream (data, offset, length); + } + + produce (list, input); + } catch (Exception e) { for (int i = 0; i < list.size (); i++) @@ -109,5 +131,5 @@ public abstract class ImageDecoder implements ImageProducer { } - abstract void produce (Vector v, FileInputStream is) throws IOException; + abstract void produce (Vector v, InputStream is) throws IOException; } |