Results 1 to 1 of 1
Thread: File Streaming in Java
- 01-18-2011, 08:57 PM #1Member
- Join Date
- Jan 2011
- Rep Power
File Streaming in Java
I'm currently developing 3D graphics application using JOGL (Java OpenGL binding). In brief, I have a huge landscape binary file. Due to its size, I have to stream terrain chunks in the run-time. Therefore, we explicitly see the random access concern. I have already finished the first (and dirty :)) implementation (perhaps it is multi-threaded), where I'm using a foolish approach... Here is the initialization of it:
dataInputStream = new DataInputStream(new BufferedInputStream(fileInputStream,4 * 1024); dataInputStream.mark(dataInputStream.available());
dataInputStream.reset(); dataInputStream.skipBytes(offset); dataInputStream.read(whatever I need...);
- Byte Buffers and Non-Heap Memory - Mr. Gregory seems to be literate in Java NIO.
- Java tip: How to read files quickly - That's an interesting benchmark.
- Articles: Tuning Java I/O Performance - Simple Sun recommendations, but please scroll down and have a look at "Random Access" section there; they show a simple implementation of RandomAccessFile (RAF) with self-buffering improvement.
Mr. Gregory provides several *.java files in the end of his article. One of them is a benchmarking between FileChannel + ByteBuffer + Mapping (FBM) and RAF. He says that he noticed 4x speedup when using FBM compared to RAF. I have ran this benchmark in the following conditions:
- The offset (e. g. place of access) is generated randomly (in the file scope, e. g. 0 - file.length());
- File size is 220MB;
- 1 000 000 accesses (75% reads and 25% writes)
The results were stunning:
~ 28 sec for RAF! ~ 0.2 sec for FBM!
However, his implementation of RAF in this benchmark doesn't have self-buffering (the 3rd article tells about one), so I guess it is the "RandomAccessFile.seek" method calling, who drops performance so hard.
Ok, now after all those things I've learnt there is 1 question and 1 dilemma :)
Question: When we are mapping a file using "FileChannel.map" does Java copy the whole file contents into the MappedByteBuffer? Or does it just emulate it? If it copies, then using FBM approach is not suitable for my situation, is it?
Dilemma: Depends on your answers on the question...
- If mapping copies a file, then it seems like I have only 2 possible solutions to go: RAF + self-buffering (the one from the 3rd article) or make use of position in FileChannel (not with mapping)... Which one would be better?
- If mapping doesn't copy a file, then I have 3 options: two previous ones and FBM itself.
P. S. I would like to receive a fulfilled answer with advices, since I'm not able to find the consistent information over this topic in the internet.
- By anniya0n in forum JDBCReplies: 3Last Post: 05-08-2013, 03:21 PM
- By Noktasal in forum NetworkingReplies: 0Last Post: 12-18-2009, 04:38 PM
- By jfxdd in forum Advanced JavaReplies: 2Last Post: 11-24-2009, 07:13 PM
- By zildjohn01 in forum CLDC and MIDPReplies: 0Last Post: 11-22-2008, 05:27 AM
- By arnab321 in forum CLDC and MIDPReplies: 1Last Post: 10-11-2008, 03:08 PM