R
Ron
The following code does not work ("file" and "image" are members of the
class; nextNumber(InputStream) returns the next number in the
InputStream):
public void write(PrintStream stream) throws IOException {
FileInputStream in = new FileInputStream(file);
int size = in.available();
stream.println(size);
byte[] b = new byte[in.available()];
in.read(b);
stream.write(b, 0, size);
in.close();
}
public void read(InputStream stream) throws IOException {
int size = (int)nextNumber(stream);
byte[] buf = new byte[size];
stream.read(buf, 0, size);
ByteArrayInputStream imageStream = new ByteArrayInputStream(buf);
image = ImageIO.read(imageStream);
}
"image" is null when I run this code. Suffice to say, the code
"ImageIO.read(file)" works. Can anyone see a problem with this? Thanks.
Ron
class; nextNumber(InputStream) returns the next number in the
InputStream):
public void write(PrintStream stream) throws IOException {
FileInputStream in = new FileInputStream(file);
int size = in.available();
stream.println(size);
byte[] b = new byte[in.available()];
in.read(b);
stream.write(b, 0, size);
in.close();
}
public void read(InputStream stream) throws IOException {
int size = (int)nextNumber(stream);
byte[] buf = new byte[size];
stream.read(buf, 0, size);
ByteArrayInputStream imageStream = new ByteArrayInputStream(buf);
image = ImageIO.read(imageStream);
}
"image" is null when I run this code. Suffice to say, the code
"ImageIO.read(file)" works. Can anyone see a problem with this? Thanks.
Ron