This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Writing and Reading JPEGS from stream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Writing and Reading JPEGS from stream" Watch "Writing and Reading JPEGS from stream" New topic
Author

Writing and Reading JPEGS from stream

Bryant Lee
Greenhorn

Joined: Feb 24, 2004
Posts: 9
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

Joined: Feb 24, 2004
Posts: 9
I forgot to add that the error actually comes when I try to change the currFrame to a bufferedImage.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing and Reading JPEGS from stream
 
Similar Threads
bytearray image decoding
JAI blurry images
sending images over server socket to browser page
Reading word document
Understanding Byte Data and Character Encoding