Reading a fle format thats part ascii and part binary

Hey

I'm trying to write a importer for the PLY filke format. That file format starts of with a header in ascii and then continues with either the data in ascii or in binary. When the data is in ascii I have no problem reading the file but when the data is in binary I'm noth quite sure how I should do it. Right now I do something like this:

BufferedInputStream stream =new BufferedInputStream(new FileInputStream(file));// I first create this

BufferedReader reader =new BufferedReader(new InputStreamReader(stream));// then this is for reader ascii

DataInputStream dataInputStream =new DataInputStream(stream);// And this is for reading binary

Then I read the ascii header with the BuffereReader and then wheter I turns out that the data is in ascii I countine reading with the reader, otherwise I start reading with the DataInputStream. But the data from the DataInputStream is not the same as I get from the BufferedReader. I try it on these files that are in diffrent endians and either ascii ot binary

http://www.cs.ucl.ac.uk/staff/Joao.Oliveira/ply.html in the Nbunny.zip.

Anyone that can help me with this? Or know about a PLY file reader in java already?

Discordia

Message was edited by:

Discordia

[1542 byte] By [Discordiaa] at [2007-10-3 3:00:37]
# 1
I would read the format in two phases.1. read the header in ascii2. close the file3. re-open file and skip the header4. read the binary
klana001a at 2007-7-14 20:50:13 > top of Java-index,Other Topics,Java Game Development...
# 2

DataInputStream is NOT the right class to use for general binary input. It is used only for the specific purpose of reading Java primitives. The input obviously needs to be in the right format for that to work, i.e. it needs to be written using a DataOutputStream.

I would read everything using an InputStream, not a reader. Store the bytes of the header until you reach the end of the header (not sure how to determine that since I don't know the fileformat). Then convert those bytes into a String using the proper charset ("US-ASCII" in this case, if by "ascii" you really mean ASCII).

Then just continue reading the binary data.

Herko_ter_Horsta at 2007-7-14 20:50:13 > top of Java-index,Other Topics,Java Game Development...
# 3
nm
Herko_ter_Horsta at 2007-7-14 20:50:13 > top of Java-index,Other Topics,Java Game Development...