48 |
Vector consumers = new Vector (); |
Vector consumers = new Vector (); |
49 |
String filename; |
String filename; |
50 |
URL url; |
URL url; |
51 |
|
byte[] data; |
52 |
|
int offset; |
53 |
|
int length; |
54 |
|
InputStream input; |
55 |
|
|
56 |
public static ColorModel cm; |
public static ColorModel cm; |
57 |
|
|
73 |
this.url = url; |
this.url = url; |
74 |
} |
} |
75 |
|
|
76 |
|
public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength) |
77 |
|
{ |
78 |
|
data = imagedata; |
79 |
|
offset = imageoffset; |
80 |
|
length = imagelength; |
81 |
|
} |
82 |
|
|
83 |
public void addConsumer (ImageConsumer ic) |
public void addConsumer (ImageConsumer ic) |
84 |
{ |
{ |
85 |
consumers.addElement (ic); |
consumers.addElement (ic); |
101 |
Vector list = (Vector) consumers.clone (); |
Vector list = (Vector) consumers.clone (); |
102 |
try |
try |
103 |
{ |
{ |
104 |
FileInputStream is = (url == null) ? new FileInputStream (filename) : |
// Create the input stream here rather than in the |
105 |
(FileInputStream) url.openStream(); |
// ImageDecoder constructors so that exceptions cause |
106 |
|
// imageComplete to be called with an appropriate error |
107 |
produce (list, is); |
// status. |
108 |
} |
if (url != null) |
109 |
|
input = url.openStream(); |
110 |
|
else |
111 |
|
{ |
112 |
|
if (filename != null) |
113 |
|
input = new FileInputStream (filename); |
114 |
|
else |
115 |
|
input = new ByteArrayInputStream (data, offset, length); |
116 |
|
} |
117 |
|
|
118 |
|
produce (list, input); |
119 |
|
} |
120 |
catch (Exception e) |
catch (Exception e) |
121 |
{ |
{ |
122 |
for (int i = 0; i < list.size (); i++) |
for (int i = 0; i < list.size (); i++) |
131 |
{ |
{ |
132 |
} |
} |
133 |
|
|
134 |
public abstract void produce (Vector v, FileInputStream is) throws IOException; |
public abstract void produce (Vector v, InputStream is) throws IOException; |
135 |
} |
} |