help ,ImageIO

Hi, I'm dynamiclly creating image files through screenshot utility of java(prog name:- Test_ScreenShot.java) and saving
them in memory sequentially(pic0.jpg,pic1.jpg....etc).Simultaneously I'm accessing the saved files from another
independent application(Prog name:- Test_Main.java) through piping(executing the application like this "Java
Test_ScreenShot|Java Test_Main").The application is in infinite loop.I'm using Version JDK 1.5
I use java ImageIO to read and write image:- My application was running well for days.But now I'm getting sudden exceptions. I got an excepton while trying to save an dynamically generated image file in the local memory using the ImageIO
class.In brief I'm getting exactly 3 types of exceptions:-
1)java.io.FileNotFoundException: pic5.jpg (Access is denied) 2)"Exception in thread "main" java.lang.NullPointerException 3)Exception in thread "main" com.sun.image.codec.jpeg.ImageFormatException: Not a JPEG file: starts with 0xff 0xd9
Here is the code snippent I wrote:
/* Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRect); // save captured image to jpg file ImageIO.write(image, "jpg", new File(outFileName));*/
And here is the exception I am finding (I never found this before, I executed the code many times ) ====================================================================================================================1)Exception Type 1:-
java.io.FileNotFoundException: pic5.jpg (Access is denied) at java.io.RandomAccessFile.open(Native Method) at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212) at javax.imageio.stream.FileImageOutputStream.<init>(FileImageOutputStream.java:44) at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(FileImageOutputStreamSpi.java:37) at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:391) at javax.imageio.ImageIO.write(ImageIO.java:1483) at Test_ScreenShot.main(Test_ScreenShot.java:112) at Test_Main.main(Test_Main.java:466) at Test_ScreenShot.main(Test_ScreenShot.java:129)
2)Exception Type 2:- "Exception in thread "main" java.lang.NullPointerException at Picture.width(Picture.java:84) at Test_Edge_Detector.not_main(Test_Edge_Detector.java:38) at Test_Main.main(Test_Main.java:88)"
===========================================================================================Now I tried the following as alternative of ImageIO(from jdk 1.2) to read image:- FileInputStream fis = new FileInputStream(file); JPEGImageDecoder jpeg = JPEGCodec.createJPEGDecoder(fis); jpeg.decodeAsBufferedImage(); fis.close(); But after running a long time suddenly its giving following exceptions:-
============================================================================================ Exception Type 3:- )
Exception in thread "main" com.sun.image.codec.jpeg.ImageFormatException: Not a JPEG file: starts with 0xff 0xd9 at sun.awt.image.codec.JPEGImageDecoderImpl.readJPEGStream(Native Method) at sun.awt.image.codec.JPEGImageDecoderImpl.decodeAsBufferedImage(Unknown Source)
Exception Type 4:- )
javax.imageio.IIOException: Not a JPEG file: starts with 0xff 0xd9 at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method) at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(Unknown Source) at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(Unknown Source) at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(Unknown Source) at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(Unknown Source) at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source) at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(Unknown Source) at javax.imageio.ImageIO.read(Unknown Source) at javax.imageio.ImageIO.read(Unknown Source) at Picture.<init>(Picture.java:22) at Test_Edge_Detector.not_main(Test_Edge_Detector.java:37) at Test_Main.main(Test_Main.java:88) Exception in thread "main" java.lang.RuntimeException: Could not open file: pic45.jpg at Picture.<init>(Picture.java:27) at Test_Edge_Detector.not_main(Test_Edge_Detector.java:37) at Test_Main.main(Test_Main.java:88)
My question is:- 1)Where is the actual problem?Is it any kind of bug? 2)I'm using the concept of piping recently to execute the application.Can it be the cause?
    When I googled I found the following informations.There is a bug in ImageIO while trying to write image file.But I'm not sure about that it will be relevent here :- 1)from sun's bug database:- http://bugs.sun.com/bugdatabase/view_bug.do?bug_idb47985
2)from SUN Developer Forums
http://forum.java.sun.com/thread.jspa?threadIDv8917&messageIDC82833
3)from Java.NET forum(here they r getting the bug while they r using createScreenCapture() method of robot class,I am
also using that in my code) http://forums.java.net/jive/thread.jspa?messageID 3247
4)from SUN's archieve http://archives.java.sun.com/cgi-bin/wa?A2=ind0207&L=java-imageio-interest&D=0&P 83
5)Here is the actual implemetation of ImageIO class.I'm getting error at 391 no. line. http://kickjava.com/src/javax/imageio/ImageIO.java.htm
Thanks And Regards Subhadip
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.