• Post Reply Bookmark Topic Watch Topic
  • New Topic

check file whether it contains valid data

 
sowjan kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm using Apache-FileUpload to get all the datas. One of the data is my image file. I have an image file of size 6 bytes but it is corrupted one..On reading(InputStream.read()) I can get the bytes. But on opening the file manually it's showing "PNG Decode" error. Are there any code to check whether the file contains proper image or corrupted image?

Thanx
Sowjanya
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many binary file types start with a signature. Frinstance Java classes all start with x'CAFEBABE'. You might be able to tell if the first few bytes of a file match the extension, but that won't help you know if it's been truncated or corrupted in the middle.
 
sowjan kumar
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx James.....I have another idea of using javax.imageio.ImageIO. But in JSP it's not compiling and it's throwing Exception "Unabe to compile class".
As ImageIO.read(InputStream) reads after decoding the file it will be null if the image is corrupted and gives a proper bytes if the file is a valid one....Any idea as how to proceed further? Websphere supports only jdk1.3.1 and these classes are in jdk1.4.1...So Iam unable to proceed further...Can anyone plese help me as how should i proceed further

Thank you
Sowjanya
[ January 13, 2005: Message edited by: sowjan kumar ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This list of Java libraries to read and write image files looks like a good place to start.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!