• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing a file reader  RSS feed

 
harish kshatrea
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently working on a problem in which I have a file created by a proprietary codec. I know the file format specs. I have to write a file decoder such that it can send its output to a buffer. Then an executable program will take the buffer output to display an image (the file is an image file). I know how to write the code for the viewer, but I've never written code to open a file beyond the standard fopen() and fclose(). Can someone point me in the right direction?

Thanks in advance. Much appreciated.

Harish.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's fopen() and fclose()? That sounds more like <stdio.h> in C than Java

Start with the I/O section of the Java™ Tutorials, and see whether you can find anything useful there.
 
harish kshatrea
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hehe, yeah that's what I meant. I've never done anything else with a file other than fopen and fclose, which I should've made clear was being done in C.
Thanks for the update, Campbell. Much appreciated.

Cheers!
Harish.
 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
harish kshatrea
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, post my newfound information , I'll have a go at asking a better question. I have a file of a new proprietary format given to me by a client (a *.ctmraw file). I have the file format specification, and my objective is to read the file and display the image. At the moment, I've read it into a buffer and I know the headers. Stop me if I am wrong. What I do next is to read the file header, the sub headers, and the image data into different variables, and write the data into a Java2D class, right? Speaking quite simplistically, of course. Can someone point me in the right direction as to what to start with when you have a file format with just its format specifiers? I am sorry I cannot post the headers, since it is a proprietary file format. I just need a push in the right direction.
Thank you very much once again.

Harish.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The specification should tell you exactly what each byte means. For instance, for a Java class file, always starts with bytes 0xCA, 0xFE, 0xBA and 0xBE, the well-known cafebabe. Likewise, ZIP files always start with 0x50 and 0x4B, also known as PK. In the end, you will need to follow that specification, reading each byte as specified, and handling it appropriately. In your case, that could mean creating a BufferedImage or WritableRaster or something similar and setting each pixel as needed.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!