loading binary data

Started by Clockwork, April 01, 2004, 23:29:42

Previous topic - Next topic

Clockwork

I'm working on a loader for Quake 3 bsp files, and I'm curious about  how other people are getting large chunks of data off the file system and into buffers. I'm using a FileImageInputStream because that's the only input stream I could find where I could specify endian type. I can use that to read in one primative at a time, which is fine for my small Milkshape files, but I would expect it to be very slow for a quake level.
What I'm looking at right now is reading the whole vertex lump into one big byte array, then converting it into a byte buffer to pass on to lwjgl later. But I don't know if that's fast or if it will end up replicating the data in memory.

Any suggestions?

spasi

I'm using NIO. You get a Channel from a FileInputStream and you read straight to a ByteBuffer. Have you tried that?

Clockwork

No, I hadn't seen the FileChannel. That's exactly what I'm looking for, thanks.

Is there a way to control the byte ordering here, or is it not an issue? I recall having problems using a reader class from IO, which lead me to the FileImageInputStream with its setByteOrder method.

Clockwork

Wait a minute, you can't control the byte ordering on an amorphous block of data. So, I'd have to control it at the byte buffer level itself. And... yup there it is.

Thanks for getting me on track, Spasi.

spasi

You're welcome. You'll find it's actually pretty fast as well!

Clockwork

Heh, for a minute there I was starting to really miss C.  :wink: