Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing and Reading JPEGS from stream

 
Bryant Lee
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My java program is an interface to a C program which it calls with Runtime.Exec(). So I have the C program as process p. I wrap p.inputstream() with an ImageInputStream.
The C program outputs some text data, then outputs the length of the upcoming jpeg and then outputs the jpeg as binary, outputs more text data, another jpeg, text, jpeg, etc. In the java program, I read the C prog's output text with some regular expressions, then I get the length of the jpeg and do:

It works fine on my Linux machine. But on Windows XP I get the runtime error:
Premature end of jpeg file
sun.awt.image.ImageFormatException: JPEG datastream contains no image
at sun.awt.image.JPEGImageDecoder.readImage (Native Method)
at sun.awt.image.JPEGImageDecoder.produceImage
at sun.awt.image.InputStreamImageSourcce.doFetch
at sun.awt.image.Imagefetcher.fetchloop
at sun.awt.image.Imagefetcher.run
All suggestions on how to fix this are welcome. Thanks.
 
Bryant Lee
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to add that the error actually comes when I try to change the currFrame to a bufferedImage.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic