Problem with imageio: ImageReader stalls on JPEGs at ~95%

A

Aaron Davies

I'm trying to write some classes for my collaborative whiteboard to
transmit images over the network, using the javax.imageio API, but I'm
running into an odd problem: my code words fine with PNGs, but not
with JPEGs. As you can see below, I've attached a progress listener to
the reader, which reports progress up to just under 95%, then nothing.
The warning listener reports no warnings. The images are written by an
ImageWriter in another section of the code, which also uses the same
listeners, and *does* report completion w/o warnings. With PNGs, the
read completes just fine. Any help would be much appreciated; snippets
follow. (ImageStatusUpdater is a class of mine which implements
IIOReadProgressListener, IIOWriteProgressListener,
IIOReadWarningListener, and IIOWriteWarningListener.)

From the writer's code:

Socket _soc = serverSocket.accept();
ImageWriter _writer = (ImageWriter)
ImageIO.getImageWritersByFormatName(
format).next();
ImageStatusUpdater _isu = new ImageStatusUpdater();
_writer.addIIOWriteProgressListener(_isu);
_writer.addIIOWriteWarningListener(_isu);
_writer.setOutput(ImageIO.createImageOutputStream(_soc
.getOutputStream()));
_writer.write(image);

And the reader's:

Socket _socket = new Socket(ip, port);
ImageReader _ir = (ImageReader) ImageIO.
getImageReadersBySuffix(suffix).next();
ImageStatusUpdater _isu = new ImageStatusUpdater();
_ir.addIIOReadProgressListener(_isu);
_ir.addIIOReadWarningListener(_isu);
InputStream _is = _socket.getInputStream();
ImageInputStream _iis = ImageIO.createImageInputStream(_is);
_ir.setInput(_iis, true, true);
imageIcon.setImage(_ir.read(0));
 
A

ak

I'm trying to write some classes for my collaborative whiteboard to
transmit images over the network, using the javax.imageio API, but I'm
running into an odd problem: my code words fine with PNGs, but not
with JPEGs. As you can see below, I've attached a progress listener to
the reader, which reports progress up to just under 95%, then nothing.
The warning listener reports no warnings. The images are written by an
ImageWriter in another section of the code, which also uses the same
listeners, and *does* report completion w/o warnings. With PNGs, the
read completes just fine. Any help would be much appreciated; snippets
follow. (ImageStatusUpdater is a class of mine which implements
IIOReadProgressListener, IIOWriteProgressListener,
IIOReadWarningListener, and IIOWriteWarningListener.)

From the writer's code:

Socket _soc = serverSocket.accept();
ImageWriter _writer = (ImageWriter)
ImageIO.getImageWritersByFormatName(
format).next();
ImageStatusUpdater _isu = new ImageStatusUpdater();
_writer.addIIOWriteProgressListener(_isu);
_writer.addIIOWriteWarningListener(_isu);
_writer.setOutput(ImageIO.createImageOutputStream(_soc
.getOutputStream()));
_writer.write(image);

I think, that you need to flush your output stream just after writeImage.
 
A

Aaron Davies

ak said:
I think, that you need to flush your output stream just after writeImage.


I just tried it, it doesn't help. Also, why would that affect JPEGs but not PNGs?
 
R

Roedy Green

I just tried it, it doesn't help. Also, why would that affect JPEGs but not PNGs?

non-existent and irrelevant newesgroups snipped.


JPEG is a compressed format. These are notorious for not giving you
all the bytes you ask for on each read. Like GZIP you likely must be
careful with flushes, finisheds and too keep reading even after fewer
bytes than you requested.
 
D

dar7yl

Aaron Davies said:
I'm trying to write some classes for my collaborative whiteboard to
transmit images over the network, using the javax.imageio API, but I'm
running into an odd problem: my code words fine with PNGs, but not
with JPEGs. As you can see below, I've attached a progress listener to
the reader, which reports progress up to just under 95%, then nothing.

It could be that the progress is actually 100% complete, but the listener is
stalled on the proverbial event-dispatch-loop while something in the cleanup
code is infinite-looping. Just a hint to look "outside the box".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top