Bug 227236

Summary: ImageLoader does not leave stream in readable state
Product: [Eclipse Project] Platform Reporter: Mark McLaren <mark.k.mclaren>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: carolynmacleod4, remy.suen
Version: 3.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Mark McLaren CLA 2008-04-15 18:39:44 EDT
Build ID: 3.4-M6a

I need to send an image over a network as well as some other data, but
ImageLoader doesn't behave as I would expect.  Here's a JUnit test case
showing the problem (using 3.4-M6a):

public void testCanWriteAndReadBlankPic() throws Exception {
  ImageData outImg = new ImageData(200, 200, 24, new PaletteData(0, 0, 0));
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  ImageLoader outLoader = new ImageLoader();
  outLoader.data = new ImageData[] { outImg };
  outLoader.save(outStream, SWT.IMAGE_JPEG);
  outStream.write(5);
  outStream.close();

  byte[] bytes = outStream.toByteArray();

  ByteArrayInputStream inStream = new ByteArrayInputStream(bytes);
  ImageLoader inLoader = new ImageLoader();
  inLoader.load(inStream);
  assertEquals(5, inStream.read());
}


I would expect to be able to read from the stream after loading the image,
but this fails.
Comment 1 Carolyn MacLeod CLA 2008-04-16 12:45:08 EDT
Some notes:

- I tried adding the following code to the end of JPEGDecoder.loadFromByteStream(InputStream inputStream, ImageLoader loader)
(right before the ImageData is returned)

	if (cinfo.bytes_in_buffer > cinfo.bytes_offset) {
		/* Try to unread any buffered data past EOI. */
		if (cinfo.inputStream.markSupported()) {
			try {
				cinfo.inputStream.reset();
				cinfo.inputStream.skip(cinfo.bytes_offset);
			} catch (IOException e) {
				//SWT.error(SWT.ERROR_IO, e);
			}
		}
	}


I thought this would do it, but it seems that the inputStream, which is an org.eclipse.swt.internal.image.LEDataInputStream,
does not implement reset() and skip(n) so this code doesn't do anything.
Note: also need to return true in markSupported() if these methods are implemented.

I don't have time to take this further at the moment, so I'm just making these notes for when I revisit this in future. (If you'd like to try implementing and testing this and submitting a patch, that would be great!)
Comment 2 Eclipse Webmaster CLA 2019-09-06 16:10:44 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.