I have been trying to improve the speed of my way of reading large files containing floats. My first attempt gave this:
DataInputStream in=new DataInputStream(new BufferedInputStream(getClass().getResourceAsStream("/pic256/worldmap.data")));
levelCoordinatesBuffer=BufferUtil.newFloatBuffer(count*floatPerPrimitive);
for(i=0;i<count;i++)
{levelCoordinatesBuffer.put(in.readFloat());
levelCoordinatesBuffer.put(in.readFloat());
levelCoordinatesBuffer.put(in.readFloat());
levelCoordinatesBuffer.put(in.readFloat());
levelCoordinatesBuffer.put(in.readFloat());
}
My second attempt gives this:
levelCoordinatesBuffer=BufferUtil.newFloatBuffer(countfloatPerPrimitive);
try{
ByteBuffer byteBuffer = BufferUtil.newByteBuffer(countfloatPerPrimitive*BufferUtil.SIZEOF_FLOAT);
FileInputStream fis = new FileInputStream(new File(getClass().getResource("/pic256/worldmap.data").toURI()));
fis.getChannel().read(byteBuffer);
byteBuffer.position(0);
//levelCoordinatesBuffer=byteBuffer.asFloatBuffer();
levelCoordinatesBuffer.put(byteBuffer.asFloatBuffer());
//byteBuffer = null;
}
catch(URISyntaxException urise)
{
urise.printStackTrace();
}
levelCoordinatesBuffer.position(0);
The first method works but not the second. It is “as” I read only 0.0f. What seems to be wrong? How would you do it if you wanted to read plenty of floats as quick as possible?